*Create a rectangle class using all methods given below.* *Use Java*  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 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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

*Create a rectangle class using all methods given below.*

*Use Java* 

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

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: use all
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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY