Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions