Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please do in java and comments the code so i can understand Requirements: Create a Java class named MyRectangle2D.java. Your class will have double two

please do in java and comments the code so i can understand

Requirements:

  • 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

Compare the different types of employee separation actions.

Answered: 1 week ago

Question

Assess alternative dispute resolution methods.

Answered: 1 week ago

Question

Distinguish between intrinsic and extrinsic rewards.

Answered: 1 week ago