Question: use the information above to write the code for experiment 2 Experiment 2: Type the following code into the main method of Experiment_2 and try


Experiment 2: Type the following code into the main method of Experiment_2 and try to run the main method. You may have to comment out" statements as you test to see which are valid and which are not Shape S; Rectangle r = new Rectangle ( 10, 20); System.out.println( r.toString()); S = r; System.out.println( s.toString() ); Shape VAR Circle Rectangle Square / * Class Shape - BASE CLASS /* Class Circle - represents a circle of a given color. public class Circle extends Shape { private doubler; private String color; public Circle(String c) { color = c; r-0; public Circle(double rl, String c) { color=c;r=r1;} public void setRadius( double rl) {r=rl; } public double getRadius {retum r;) public void setColor( String c) { color = c; } public String getColor { return color; public double getArea {return Math.PI*r*r; } public String toString {retum String.format("%s Circle: r-%.2f", color, ); }; /* Class Square - represents a square of a given color / public class Square extends Shape { private double w; private String color: public class Shape public String toString {return String.format( "Shape"); } } /* Class Rectangle - represents a rectangle of given color */ public class Rectangle extends Shape private double 1; private double w; private String color; public Square(String e) { color: w 0; } public Square(double w, String c) public Rectangle {1-0; w=0; color="Blue"; } public Rectangle(double I, double w) {this.1 -1; this.ww; color="Blue":} public void setWidth( double w) {this.w - w; } public void setLength( double 11){this.1 -1; } public double getWidth {retum w;) public double getLength {return 1;) public void setColor( String c) color-c: public String getColor() {return color;) public double getArea { return lw:) public String toStringo return String.format("%s Rectangle size-c%.2f by %21". color, I, w): ) setColor(e); set Width(w); } public void setWidth( double wl) { this.w = w; ) public double getWidth {return w;) public void setColor String e) {color=c; } public String getColor {retum color;) public double getArea { return w*w; ) public String toStringo { return String.format("%s Square size-(%.2f by 21" color, w, w): EMPLATE Experiment_2 X Compile Undo Cut Copy Paste Find.. Close Source Code /** * Class CopyOfExperiment_2 */ import java.util.*; public class Experiment_2 { public static void main(String[] args) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
