Question: Requirements: programming language is java Create a Java class named MyRectangle2D.java. Your class will have double two variables named x and y. These will represent
Requirements:
programming language is java
Create a Java class named MyRectangle2D.java.
Your class will have double two variables named x and y. These will represent the center point of your rectangle.
Your class will have two double variables named width and height. These will represent the width and height of your rectangle.
Create getter and setter methods for x, y, width, and height.
Create a no argument constructor for your class that sets x to 0, y to 0, width to 1, and height to 1. Have this constructor output your first and last name.
Create a constructor for your class that has x, y, width, and height input parameters.
If the x or y input parameters are less than 0.0, set them to be 0.0
If the width or height input parameters are less than 1.0, set them to be 1.0
Create method myTop that returns the y coordinate of the top of the rectangle
This would be y + 0.5*height.
Create method myBottom that returns the y coordinate of the bottom of the rectangle
This would be y 0.5*height.
Create method myLeft that returns the x coordinate of the left side of the rectangle
This would be x 0.5*width.
Create method myRight that returns the x coordinate of the left side of the rectangle
This would be x + 0.5*width.
Create method getArea that returns the area of the rectangle
The area is the width * height
Create method getPerimeter that returns the perimeter of the rectangle
The perimeter is 2 * width + 2 * height
Create method contains(double inX, double inY) that returns true if the point (inX,inY) is inside the rectangle and false otherwise.
To test your program, I will create a class with a main method that creates instances of your MyRectangle2D class, calling all the constructors and method.
For example, assume a rectangle was created with x=2.0, y=1.0, width=1.0, and height=2.0
getX would return 2.0
getY would return 1.0
getWidth would return 1.0
getHeight would return 2.0
myTop would return 2.0
myBottom would return 0.0
myLeft would return 1.5
myRight would return 2.5
getArea would return 2.0
getPerimeter would return 6.0
contains(1.75,0.9) would return true
contains(2.5,2.25) would return false
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
