ESc101 Laboratory Assignment Wednesday 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. Vehicle, HeavyVehicle, LightVehicle, and ProgramClass. The classes HeavyVehicle and LightVehicle are sub classes of class Vehicle. The class Vehicle has VehicleNo, Cost, RoadTax as member data and a member function ComputeRoadTax(). i The function ComputeRoadTax is overridden in classes HeavyVehicle and LightVehicle. It calculates the Road Tax depending on the Vehicle type. In the ProgramClass, write code to take information about 10 Vehicles as input from the user including information about whether the vehicle is a LightWeight Vehicle or HeavyWeight Vehicle, compute respective objects, and save them in a single array. Compute the Road Tax for the vehicle depending on its type using a loop. Then display the Road Tax for each vehicle. The Road Tax is 10% of the cost of the vehicle for Heavy Weight vehicles and 5% for Light Weight Vehicles. ====================================================================================