In this exercise, we are going to model some behaviors of a square. Since the Square object extends the Rectangle object, we see that a lot of the information we need is stored in the superclass and we will need to access it using the super keyword. Your job is to complete the Square class, as specified within the class. Upon completion, thoroughly test out your code using the SquareTester class. ----------------------------------- public class SquareTester { public static void main(String[] args) { // Start here! } } ----------------------------------- public class Rectangle { private double width; private double height; public Rectangle(double w, double h){ width = w; height = h; } public double getWidth(){ return width; } public void setWidth(double w){ width = w; } public double getHeight(){ return height; } public void setHeight(double h){ height = h; } public String toString(){ return "Rectangle with width " + width + " and height " + height; } } ----------------------------------- public class Square extends Rectangle { // Call to the Rectangle constructor public Square(double sideLength){ } // Return either the width or height from the superclass public double getSideLength(){ } //Set both the width and height in the superclass public void setSideLength(double sideLength){ } // Get the width and/or the height from the superclass public double area(){ } // Override to read: Square with side lengths ______ public String toString(){ } }
In this exercise, we are going to model some behaviors of a square. Since the Square object extends the Rectangle object, we see that a lot of the information we need is stored in the superclass and we will need to access it using the super keyword.
Your job is to complete the Square class, as specified within the class. Upon completion, thoroughly test out your code using the SquareTester class.
-----------------------------------
public class SquareTester
{
public static void main(String[] args)
{
// Start here!
}
}
-----------------------------------
public class Rectangle {
private double width;
private double height;
public Rectangle(double w, double h){
width = w;
height = h;
}
public double getWidth(){
return width;
}
public void setWidth(double w){
width = w;
}
public double getHeight(){
return height;
}
public void setHeight(double h){
height = h;
}
public String toString(){
return "Rectangle with width " + width + " and height " + height;
}
}
-----------------------------------
public class Square extends Rectangle {
// Call to the Rectangle constructor
public Square(double sideLength){
}
// Return either the width or height from the superclass
public double getSideLength(){
}
//Set both the width and height in the superclass
public void setSideLength(double sideLength){
}
// Get the width and/or the height from the superclass
public double area(){
}
// Override to read: Square with side lengths ______
public String toString(){
}
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images