subject
Computers and Technology, 06.07.2021 09:00 mella98

CSC: Rectangles Use JAVA program. Must.

Create two classes. Class Rectangle is a class that represents an axis-aligned rectangle. Class RectangleTesteris 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

•filled –a boolean variable that is true if the rectangle is filled, and false if it is not

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, boolean filled)

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 an unfilled rectangle of width 0.1, height 0.1, color “red” and lower left vertex at coordinates (0, 0). If only the color is invalid, then only the color should be set to red.
Rectangle Methods:
double getX() - Returns the x coordinate of this object.
double getY() - Returns the y coordinate of this object.
double getWidth() - Returns the width of this object.
double getHeight() - Returns the height of this object.
String getColor() - Returns the color of this object.
boolean isFilled() - Returns whether the rectangle is filled or not
void setX(double x) - Sets the x coordinate of this object to x. If thisresults in aninvalidrectangle, it leaves the x coordinate unchanged.
void setY(double y) - Sets the y coordinate of this object to y. If thisresults in aninvalidrectangle, it leaves the y coordinate unchanged.
void setWidth(double w) - Sets thewidth of this object to w. If this results in an invalid rectangle, it leaves thewidth unchanged.
void setHeight(double h) - Sets the height of this object to h. If this results in aninvalidrectangle, it leaves the height unchanged.
void setColor (String c) - Sets the color of this object to c. If c is invalid, it leaves the color coordinate unchanged.
void setFill (boolean f) - Sets the filled variable to f.
String toString() - Returns a String representation of the rectangle containing the values of all instance variables.
boolean equals(Rectangle rect) - Returns true if rect represents the same rectangle as this object, and false otherwise.
double computePerimeter() - Computes and returns the perimeter of this rectangle
double computeArea() - Computes and returns the area of this rectangle
boolean containsPoint(double x, double y) - Returns true if this rectangle contains point (x, y)
boolean containsRectangle(Rectangle rect) - Returns true if this rectangle contains rectangle rect
boolean intersects(Rectangle rect) - Returns true if rectangle rect and this rectangle intersect.
static boolean isValid(double x, double y, double w, double h) - Static method. Returns true if the rectangle with lower leftvertex at (x, y), width w and height h is valid, and false otherwise.
void show() - Displays the rectangle on the screen. See details below.

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);
•polygon or filledPolygon to draw the rectangle. Refer to the documentation for how to use this method.
Class RectangleTester:
This classshould be your driver class andshould contain the mainmethod. For each method in your class Rectangle, your mainmethod in RectangleTestershould have at least one test case that tests that method.

To display a rectangle, you will use the StdDraw class. Documentation for the class can be found here: https://introcs. cs. princeton. edu/java/stdlib/javadoc/StdDraw. html

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:40, vanessacasillas452
In the lab, which of the following displayed a list of all installed services and included a description of the service, the current state, and whether the service started automatically or manually? a. the services manager b. the applications summary c. the recommended services d. list the safe services list
Answers: 2
image
Computers and Technology, 23.06.2019 00:20, kathlynskare06
Ihave been given the number of guns per 100, and the total firearm-related deaths per 100,000. i have to find the actual number of guns per country and actual number of gun-related deaths. if somebody could show me how to do 1 question, i can finish the rest, i am just confused. tia
Answers: 3
image
Computers and Technology, 23.06.2019 00:30, devenybates
Which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
image
Computers and Technology, 23.06.2019 02:30, paolaviviana
Experimental data that is expressed using numbers is said to be
Answers: 1
You know the right answer?
CSC: Rectangles Use JAVA program. Must.

Create two classes. Class Rectangle is a class...

Questions in other subjects: