ESc101 Laboratory Assignment Monday of Week of 1/11/04 The assignment consists of two parts A and B. In part A, you have to run the programs given and give explanation for the results obtained. In part B you have to write a Java Program. ======= PART A ======= 1) class A { private int i,j; A(int x, int y) { i = x; j = y; } A() { i = 0; j = 0; } void setA(int x, int y) { i = x; j = y; } int getAi() { return i; } int getAj() { return j; } } class B extends A { private int total; B() { total = 0; } void setTotal() { total = i + j; } int getTotal() { return total; } } class prog1 { public static void main(String args[]) { B obj = new B(); obj.setTotal(); System.out.println("\n Value of total = " + obj.getTotal()); } } ------------------------------------------------------------------------------ 2) class A { private int i,j; A(int x, int y) { i = x; j = y; } A() { i = 0; j = 0; } void setA(int x, int y) { i = x; j = y; } int getAi() { return i; } int getAj() { return j; } } class B extends A { private int total; B() { super(); total = 0; } B(int x, int y) { super(x,y); total = 0; } void setTotal() { total = getAi() + getAj(); } int getTotal() { return total; } } class prog2 { public static void main(String args[]) { B obj = new B(10,15); obj.setTotal(); System.out.println("\n Value of total = " + obj.getTotal()); } } ---------------------------------------------------------------------- 3) class superclass { int i; void calc(int x) { System.out.println("\n The value = " + (x+i)); } int getsuperi() { return i; } void setsuperi(int x) { i = x; } } class subclass extends superclass { int i; void calc(int x) { System.out.println("\n The value = " + (super.i + i + x)); } void calc(float x) { System.out.println("\n The value = " + (super.i * x + i)); } int geti() { return i; } void seti(int x) { i = x; } } class prog3 { public static void main(String args[]) { subclass ob = new subclass(); ob.seti(20); ob.setsuperi(35); superclass sup_obj = ob; sup_obj.calc(10); superclass obj2 = new superclass(); obj2.calc(4); } } -------------------------------------------------------------------- 4) Add the following statement to the main function in the above program after the last statement. Run the program and justify the outcome. sup_obj.calc((float)4.0); ================================================================================== PART B ======= Write a program with four classes. Student, Undergraduate, PostGraduate, and ProgramClass. The classes Undergraduate and Postgraduate are sub classes of class Student. The class Student has name, marks, and grade as member data and a member function ComputeGrade(). The function ComputeGrade is overridden in classes Undergraduate and Postgraduate. It calculates the grade for the student depending on marks and prints out the grade. In the ProgramClass, write code to take the marks and names of 10 students as input from the user and information about whether the student is an Undergraduate Student or a Postgraduate Student, create respective objects, and save them in a single array. Then, compute and print the appropriate grade for the students using a loop statement. The criteria for calculating the grade for Student is : marks>=50 ==> A marks>=40 ==> B marks>=30 ==> C marks>=20 ==> D marks<20 ==> F The criteria for calculating the grade for Undergraduate Student is : marks>=70 ==> A marks>=60 ==> B marks>=40 ==> C marks>=30 ==> D marks<30 ==> F The criteria for calculating the grade for Postgraduate Student is : marks>=80 ==> A marks>=70 ==> B marks>=50 ==> C marks>=40 ==> D marks<30 ==> F