Question: ex.1 Rewrite the top class Shape and its lower classes Circle, Rectangle, and Square with respect to the following class charts. (2) Subclass Circle and

ex.1 Rewrite the top class Shape and its lower classes Circle, Rectangle, and Square with respect to the following class charts. (2) Subclass Circle and Rectangle shall redefine abstract methods getArea() and getPerimeter(), provide appropriate implementation, and so shall be the case with toString(). Write these sentence-related test classes, including polyformity, and describe the output results. Some sentences may also have a compilation error, which explains the error.

Shape s1 = new Circle(5.5, "RED", false); // Upcast Circle to Shape System.out.println(s1); // which version? System.out.println(s1.getArea()); // which version? System.out.println(s1.getPerimeter()); // which version? System.out.println(s1.getColor()); System.out.println(s1.isFilled()); System.out.println(s1.getRadius()); Circle c1 = (Circle)s1; // Downcast back to Circle System.out.println(c1); System.out.println(c1.getArea()); System.out.println(c1.getPerimeter()); System.out.println(c1.getColor()); System.out.println(c1.isFilled()); System.out.println(c1.getRadius()); Shape s2 = new Shape(); Shape s3 = new Rectangle(1.0, 2.0, "RED", false); // Upcast System.out.println(s3); System.out.println(s3.getArea()); System.out.println(s3.getPerimeter()); System.out.println(s3.getColor()); System.out.println(s3.getLength());

Rectangle r1 = (Rectangle)s3; // downcast System.out.println(r1); System.out.println(r1.getArea()); System.out.println(r1.getColor()); System.out.println(r1.getLength()); Shape s4 = new Square(6.6); // Upcast System.out.println(s4); System.out.println(s4.getArea()); System.out.println(s4.getColor()); System.out.println(s4.getSide()); // Take note that we downcast Shape s4 to Rectangle, // which is a superclass of Square, instead of Square Rectangle r2 = (Rectangle)s4; System.out.println(r2); System.out.println(r2.getArea()); System.out.println(r2.getColor()); System.out.println(r2.getSide()); System.out.println(r2.getLength()); // Downcast Rectangle r2 to Square Square sq1 = (Square)r2; System.out.println(sq1); System.out.println(sq1.getArea()); System.out.println(sq1.getColor()); System.out.println(sq1.getSide()); System.out.println(sq1.getLength());

ex.1 Rewrite the top class Shape and its lower classes Circle, Rectangle,

write java code plz:)

> Shape #color : St ring #fil led: boolean +Shape() +Shape (color:String,filled:boolean) +getColor ):String +setColor (color:String):void +isFilled ():boolean +setFilled (filled:boolean) void +getArea() :double +getPerimeter:double +toString ):String Circle Rectangle #radus : double +Circle() +Circle(radius: double) +Circle(radius: double, #width: double #length double +Rectangle) +Rectangle(width:double,length:double) +Rectangle(width:double,legth:double, color:String,filled:boolean) getRadius():double +setRadius(radius:double):void +getArea():double +getPerimeter) :double +toString ):String color:String,filled:boolean) +getWidth):double +setwidth(width:double)void getLength():double +setLength(legnth:double):void +getArea():double +getPerimeter):double +toString):String Square +Sqare() +Square(side:double) Square(side:double,color:String, filled:boolean) +getSide():double +setSide(side:double) :void +setWidth (side: double):void +setLength(side :double):void +toString() String

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!