Question: use the information above to write a code for experiment 5 Experiment #5: Type the following code into the main method of Experiment_5 and try



Experiment #5: Type the following code into the main method of Experiment_5 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 si Rectangle r = new Rectangle( 10, 20); Square sg = new Square ( 4, "Blue"); S; System.out.println( s.getWidth() ); 7 Statement #1 S-sq; System.out.println( ((Rectangle)s).getWidth()); // Statement #2 rsa; System.out.println( r.getWidth()); // Statement #3 // Statement #4 39 - r; System.out.println( sq.getWidth()); Rectangle x Compile Undo Cut Copy Paste Find... Close Source Code /** * Class Rectangle - represents a rectangle of given color */ public class Rectangle { private double 1; private double w; private String color; public Rectangle() public Rectangle (double 1, double w) public void setWidth( double w) public void setLength( double 11) public double getWidth() public double getLength() public void setColor( String c) public String getColor public double getArea { 1=0; w=0; color="Blue";} { this.l = 1; this.w = w; color="Blue { this.w = w; } { this.1 1; } { return w; } { return 1; } { color = c; } { return color; } { return 1*W; } public String toString() { return String.format("%s Rectangle size=(%.2f by %.2f)", color, 1, w); } TEMPLATE Square X Compile Undo Cut Copy Paste Find... Close Source Code * Class Square - represents a square of a given color */ public class Square { private double w; private String color; public Square(String c) public Square (double w, String c) { color=c; w=0; } setColor(c); setWidth(); } public void setWidth( double w1) { this.w = w1; } public double getWidth() { return w; } public void setColor( String c) { color = c; } public String getColor() { return color; } public double getArea() { return w*w; } public String toString() { return String.format("%s Square size=(%.2f by .2f)", color, w, w); } Experiment_5 x Compile Undo Cut Copy Paste Find... Close Source Code /** # Class Experiment_5 */ import java.util.*; public class Experiment_5 { 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
