Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UBT University of Business and Techno ege of Engineering omputer Programming-2 Q

ID: 3868301 • Letter: U

Question


UBT University of Business and Techno ege of Engineering omputer Programming-2 Qucstion A (10 the following source codes. utput that will be printed on the screen in each of ht if (i3) continue; s~.print( if(i6) * 100 '®, .. ); + break; 2 class SquareTest class Square private double PI = 3.14; public double dimension; public static void main(String[ args) Square s1 = new Square(); Square) dimension 5; System.out.println("area: "s1.getArea()); Square s2 = new Square(10); System.out println("area: " s2.getArea()); Square (double x)t dimensionx; s2.setDimentions (15); System.out.println("area: s2.getArea()) public void setDimension (double x) dimension x; a. public double getArea() return dimension dimension; //end class

Explanation / Answer

1) It will print

0

100

200

400

500

600

and the table is as below

2)

a) Here it is calling getArea function with s1 object which will call non parameterized constructor and that constructor is setting dimension = 5 so getArea will return dimension*dimension which will be 5*5 and as its double value so 25.00 will be printed.

b) Here it is calling getArea function with s2 object which will call parameterized constructor of class square and assign dimension value which is passed to this constructor that is dimension = 10 so now getArea will return 10*10 i.e. 100.00

c) Here it is first calling setDimension function on object s2 which will now set the value of dimension to 15 hence getArea will return 15*15 i.e. 225.00

i i<10 i++ if(i==3) print(i*100 +", ") if(i==6) 0 T 1 F 0*100 = 0 F 1 T 2 F 1*100 = 100 F 2 T 3 F 2*100 = 200 F 3 T 4 T (continue and no further line in loop of this iteration will execute and loop will continue for next iteration) 4 T 5 F 4*100=400 F 5 T 6 F 5*100=500 F 6 T 7 F 6*100= 600 T(break from loop and no further iteration will execute)