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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
Which of the following commands is more recommended while creating a bot?
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
This question involves a class named textfile that represents a text file. public class textfile { private string filename; private string filename; private arraylist words; // constructors not shown // postcondition: returns the number of bytes in this file public int filesize() { } // precondition: 0 < = index < words.size() // postcondition: removes numwords words from the words arraylist beginning at // index. public void deletewords(int index, int numwords) { } // precondition: 0 < = index < = words.size() // postcondition: adds elements from newwords array to words arraylist beginning // at index. pub lic voidaddwords(int index, string[] newwords) { } // other methods not shown } complete the filesize() method. the filesize() is computed in bytes. in a text file, each character in each word counts as one byte. in addition, there is a space in between each word in the words arraylist, and each of those spaces also counts as one byte. for example, suppose the words arraylist stores the following words: { mary had a little lamb; its fleece was white as snow. } the filesize() method would compute 4 + 3 + 1 + 6 + 5 + 4 + 6 + 3 + 5 + 2 + 5 as the sum of the lengths of each string in the arraylist. the value returned would be this sum plus 10, because there would also be 10 spaces in between the 11 words. complete the filesize() method below: // postcondition: returns the number of bytes in this file public int filesize() { }
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
question
Computers and Technology, 24.06.2019 10:30
Which of the following types of software is most applicable to the promotion of new products through advertising? a.databases b. spreadsheets c. web design programs d. word processing tools
Answers: 2
You know the right answer?
CSC: Rectangles Use JAVA program. Must.

Create two classes. Class Rectangle is a class...
Questions
question
Mathematics, 05.03.2021 19:50
question
Mathematics, 05.03.2021 19:50
question
English, 05.03.2021 19:50
question
Health, 05.03.2021 19:50
question
English, 05.03.2021 19:50
question
English, 05.03.2021 19:50
Questions on the website: 13722363