Question: Experiment #4: Type the following code into the main method of Experiment_4 and try to run the main method. You may have to selectively comment


Experiment #4: Type the following code into the main method of Experiment_4 and try to run the main method. You may have to selectively comment out" portions of the code in order to test cach statement. Shape s; Rectangle r = new Rectangle ( 10, 20); Circle c = new Circle ( 2, "Blue"); SI // Statement 1 17 Statement #2 System.out.println( r.getColor(); System.out.println(s.getColor() ); System.out.println( s.getWidth(); System.out.println ((Rectangle)).getWidth() / Statement #3 >> // Statement #4 3-C; System.out.println ((Rectangle)).getWidth() ) // Statement 65 ACTIVITY: Now make the following modifications * Class Shape - BASE CLASS / Class Circle - represents a circle of a given color. . public class Circle extends Shape { private double r; public class Shape private String color; public void setColor( String e) {color-c} public String getColor() { return color: public String toString { return String.format( "Shape"); } public Circle(String c) setColor(c); - 0; } public Circle(double rl, String e) { setColor(c); r-rl:} public void setRadius( double rl) (r rl; } public double getRadius {retum r; } public double getArea {return Math.PIr*r; } public String toStringo { return String.format("%s Circle: =%.2f", getColor,r); }; 3 } / Class Rectangle - represents a rectangle of given color public class Rectangle extends Shape Class Square - represents a square of a given color public class Square extends Shape private double w; private double 1; private double w; public Rectangle (1-0;w; setColor("Blue"):) public Rectangle(double I, double w) (this.1 -1; this.w w, setColor("Blue"); }; public void setWidth double w) this.ww; public void setlength double 11) (this.1 -1; public double get Width return w;) public double getlength (return :) public double getAreal { return l'w;) public String toString return String.format("%s Rectangle size-f%2fby%20". getColor, Iw):) public Square(String c) { setColor(e); w0; } public Square(double w, String ) setColor(e); setWidth(w); 2 public void setWidth double wl) (this.w-wl; } public double get Width {retum w public double get Area retum w w;) public String toString return String.format("%s Square size-(%.2fby 20" getColor, w, w):) Shape Class Circle - represents a circle of a given color. NAR Circle Rectangle public class Circle extends Shape { private double r; Square Class Shape - BASE CLASS ublic class Shape private String color; public void setColor( String e) {color-c:) public String getColor() {retum color:) public String toString { return String.format( "Shape"); } public Circle(String c) { color-c: 0; } public Circle(double rl, String c) { color-c:r=r1;) public void setRadius( double rl) {r=rl; } public double getRadius {retum r; } public double getArea() { return Math.PI*r*r; } public String toString { return String.format("%s Circle: r-%.2f", color.r); }; > /* *Class Rectangle - represents a rectangle of given color e/ public class Rectangle extends Shape private double 1; private double w; Class Square - represents a square of a given color / public class Square extends Shape private double w; public Rectangle (1-0; wo: color "Blue" 3 public Rectangle(double I, double w) (this.I - 1; this.ww, color-"Blue" :) public void set Width(double w) (this.ww ) public void setLength double II) (this.I - 1; } public double getWidth (rotum w; ) public double getLength() (return 1; ) public double getArea() return I'w:) public String toString return String.format("%s Rectangle size-(%.2f by %21)", color,1, w):) public Square(String e) { color: w-0; public Square(double w, String e) { setColor(e): setWidth(w); 3 public void setWidth double wl) { this.w-wl; } public double get Width (retum w;) public double getArea) (return w'w;) public String toStringo (return String.format("%s Square size-f%.2f by 21", color, w, w); ) Experiment #4: Type the following code into the main method of Experiment_4 and try to run the main method. You may have to selectively comment out" portions of the code in order to test cach statement. Shape s; Rectangle r = new Rectangle ( 10, 20); Circle c = new Circle ( 2, "Blue"); SI // Statement 1 17 Statement #2 System.out.println( r.getColor(); System.out.println(s.getColor() ); System.out.println( s.getWidth(); System.out.println ((Rectangle)).getWidth() / Statement #3 >> // Statement #4 3-C; System.out.println ((Rectangle)).getWidth() ) // Statement 65 ACTIVITY: Now make the following modifications * Class Shape - BASE CLASS / Class Circle - represents a circle of a given color. . public class Circle extends Shape { private double r; public class Shape private String color; public void setColor( String e) {color-c} public String getColor() { return color: public String toString { return String.format( "Shape"); } public Circle(String c) setColor(c); - 0; } public Circle(double rl, String e) { setColor(c); r-rl:} public void setRadius( double rl) (r rl; } public double getRadius {retum r; } public double getArea {return Math.PIr*r; } public String toStringo { return String.format("%s Circle: =%.2f", getColor,r); }; 3 } / Class Rectangle - represents a rectangle of given color public class Rectangle extends Shape Class Square - represents a square of a given color public class Square extends Shape private double w; private double 1; private double w; public Rectangle (1-0;w; setColor("Blue"):) public Rectangle(double I, double w) (this.1 -1; this.w w, setColor("Blue"); }; public void setWidth double w) this.ww; public void setlength double 11) (this.1 -1; public double get Width return w;) public double getlength (return :) public double getAreal { return l'w;) public String toString return String.format("%s Rectangle size-f%2fby%20". getColor, Iw):) public Square(String c) { setColor(e); w0; } public Square(double w, String ) setColor(e); setWidth(w); 2 public void setWidth double wl) (this.w-wl; } public double get Width {retum w public double get Area retum w w;) public String toString return String.format("%s Square size-(%.2fby 20" getColor, w, w):) Shape Class Circle - represents a circle of a given color. NAR Circle Rectangle public class Circle extends Shape { private double r; Square Class Shape - BASE CLASS ublic class Shape private String color; public void setColor( String e) {color-c:) public String getColor() {retum color:) public String toString { return String.format( "Shape"); } public Circle(String c) { color-c: 0; } public Circle(double rl, String c) { color-c:r=r1;) public void setRadius( double rl) {r=rl; } public double getRadius {retum r; } public double getArea() { return Math.PI*r*r; } public String toString { return String.format("%s Circle: r-%.2f", color.r); }; > /* *Class Rectangle - represents a rectangle of given color e/ public class Rectangle extends Shape private double 1; private double w; Class Square - represents a square of a given color / public class Square extends Shape private double w; public Rectangle (1-0; wo: color "Blue" 3 public Rectangle(double I, double w) (this.I - 1; this.ww, color-"Blue" :) public void set Width(double w) (this.ww ) public void setLength double II) (this.I - 1; } public double getWidth (rotum w; ) public double getLength() (return 1; ) public double getArea() return I'w:) public String toString return String.format("%s Rectangle size-(%.2f by %21)", color,1, w):) public Square(String e) { color: w-0; public Square(double w, String e) { setColor(e): setWidth(w); 3 public void setWidth double wl) { this.w-wl; } public double get Width (retum w;) public double getArea) (return w'w;) public String toStringo (return String.format("%s Square size-f%.2f by 21", color, w, w); )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
