Question
Project Details: For this project you will have to write two classes. Class Rectangle is a class that represents an axis-aligned rectangle. Class RectangleTester is
Project Details:
For this project you will have to write two classes. Class Rectangle is a class that represents an axis-aligned rectangle. Class RectangleTester is the driver class, used to test the Rectangle class.
Class Rectangle: An instance of the class Rectangle represents a valid axis-aligned rectangle. It has several instance variables that one needs to use to describe a rectangle, as well as methods that operate on these variables.
Rectangle instance variables:
Class Rectangle will have the following instance variables:
x a double that represents the x coordinate of the lower left vertex of the rectangle
y a double that represents the y coordinate of the lower left vertex of the rectangle
width a double that represents the width of the rectangle
height a double that represents the height of the rectangle
color a String that represents the color of the rectangle
For the rectangle to be valid, the coordinates of all vertices must be between 0 and 1 inclusive. The color can be one of the following: black, red, green, blue.
Rectangle constructor:
The constructor should be:
Rectangle (double x, double y, double height, double width, String color).
Parameters are, in order, the x and y coordinates of the lower left corner, the height, the width, and the color of the rectangle. The constructor should check that these values represent a valid rectangle. If they do, then it should initialize the rectangle to these values. Otherwise, the date rectangle should be initialized to a rectangle of width 1, height 1, color red and lower left vertex at coordinates (0, 0).
Make sure that the names of your methods match those listed above exactly, including capitalization. The number of parameters and their order must also match. You can change the parameter names if you want. All methods should be public. To display a rectangle, use the StdDraw class. You will need to use the following static methods:
setPenColor(color) sets the color of the pen. You can use the following colors: StdDraw.RED, StdDraw.BLUE, StdDraw.GREEN, StdDraw.BLACK. Example: StdDraw.setPenColor(StdDraw.RED);
line(x0, y0, x1, y1) draw a line in the current pen color from point (x0, y0) to point(x1, y1). Example: StdDraw.line(x, y, x+w, y+h);
Class RectangleTester:
This class should be your driver class and should contain the main method. For each method in your class Rectangle, your main method in RectangleTester should have at least one test case that tests that method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started