Question: public class Rectangle implements Shape { public class Rectangle implements Shape { private int length; / / length units along x axis private int height;

public class Rectangle implements Shape {public class Rectangle implements Shape {
private int length; //length units along x axis
private int height; //height units along y axis
private Point position; // position is the (x,y) coordinates of lower left corner of the rectangle
/*
* Purpose: initializes this Rectangle with length and height of 0
* and position to new Point at 0,0
* Parameters: none
*/
public Rectangle(){
this.length =0;
this.height =0;
this.position = new Point();
}
/*
* Purpose: initializes this Rectangle with given length and height
* and position to new Point at 0,0
* Parameters: int length, int height
* Precondition: given length and height >=0
*/
public Rectangle(int length, int height){
this.length = length;
this.height = height;
this.position = new Point();
}
/*
* Purpose: initializes this Rectangle with given length, height and position
* Parameters: int length, int height, Point position
* Precondition: given length and height >=0, position is not null
*/
public Rectangle(int length, int height, Point position){
this.length = length;
this.height = height;
this.position = position;
}
/*
* Purpose: prints a message about the characteristics of this Rectangle
* Parameters: none
* Returns: void
*/
public void printCharacteristics(){
if (length > height){
System.out.println("long rectangle");
} else if (height > length){
System.out.println("tall rectangle");
} else {
System.out.println("square");
}
}
public String toString(){
return "Rectangle of dimensions: "+ length +" by "+ height +" at Point: "+ position;
}
}
private int length; //length units along x axis
private int height; //height units along y axis
private Point position; // position is the (x,y) coordinates of lower left corner of the rectangle
/*
* Purpose: initializes this Rectangle with length and height of 0
* and position to new Point at 0,0
* Parameters: none
*/
public Rectangle(){
this.length =0;
this.height =0;
this.position = new Point();
}
/*
* Purpose: initializes this Rectangle with given length and height
* and position to new Point at 0,0
* Parameters: int length, int height
* Precondition: given length and height >=0
*/
public Rectangle(int length, int height){
this.length = length;
this.height = height;
this.position = new Point();
}
/*
* Purpose: initializes this Rectangle with given length, height and position
* Parameters: int length, int height, Point position
* Precondition: given length and height >=0, position is not null
*/
public Rectangle(int length, int height, Point position){
this.length = length;
this.height = height;
this.position = position;
}
/*
* Purpose: prints a message about the characteristics of this Rectangle
* Parameters: none
* Returns: void
*/
public void printCharacteristics(){
if (length > height){
System.out.println("long rectangle");
} else if (height > length){
System.out.println("tall rectangle");
} else {
System.out.println("square");
}
}
public String toString(){
return "Rectangle of dimensions: "+ length +" by "+ height +" at Point: "+ position;
}
}

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!