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, 23.06.2019 02:00
Consider the following function main: int main() { int alpha[20]; int beta[20]; int matrix[10][4]; . . } a. write the definition of the function inputarray that prompts the user to input 20 numbers and stores the numbers into alpha. b. write the definition of the function doublearray that initializes the elements of beta to two times the corresponding elements in alpha. make sure that you prevent the function from modifying the elements of alpha. c. write the definition of the function copyalphabeta that stores alpha into the first five rows of matrix and beta into the last five rows of matrix. make sure that you prevent the function from modifying the elements of alpha and beta. d. write the definition of the function printarray that prints any onedimensional array of type int. print 15 elements per line. e. write a c11 program that tests the function main and the functions discussed in parts a through d. (add additional functions, such as printing a two-dimensional array, as needed.)
Answers: 3
question
Computers and Technology, 23.06.2019 16:00
Helen is having a meeting with her colleagues in her company. they are working on the goals and objectives for the coming year. they want to ensure that these goals and objectives of the processes involved are properly evaluated. which system can helen and her colleagues apply to evaluate this? helen and her colleagues require a blank to evaluate the goals and objectives.
Answers: 2
question
Computers and Technology, 23.06.2019 16:30
Monica and her team have implemented is successfully in an organization. what factor leads to successful is implementation? good between different departments in an organization leads to successful is implementation.
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
Write a program that displays the following menu: geometry calculator 1. calculate the area of a circle 2. calculate the area of a rectangle 3. calculate the area of a triangle 4. quit enter your choice (1-4): if the user enters 1, the program should ask for the radius of the circle and then display its area. use the following formula: area = ď€(the square of r) use 3.14159 for ď€ and the radius of the circle for r. if the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. use the following formula: area = length * width if the user enters 3, the program should ask for the length of the triangle’s base and its height, and then display its area. use the following formula: area = base * height * .5 if the user enters 4, the program should end. input validation: display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height. note: if the user enters an improper menu choice (1-4), the program prints "the valid choices are 1 through 4. run the program again and select one of those." if the user enters a negative radius, the program prints "the radius can not be less than zero." if the user enters a negative value for height or base, the program prints "only enter positive values for base and height."
Answers: 1
You know the right answer?
CSC: Rectangles Use JAVA program. Must.

Create two classes. Class Rectangle is a class...
Questions
question
Mathematics, 28.09.2021 22:30
question
Mathematics, 28.09.2021 22:30
Questions on the website: 13722363