Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Just for JAVA Define the Rectangle2D class that contains: Double data fields named xpos, ypos (that specify the top left comer of the rectangle), width

Just for JAVA

image text in transcribed

Define the Rectangle2D class that contains: Double data fields named xpos, ypos (that specify the top left comer of the rectangle), width and height. (assume that the rectangle sides are parallel to the x and y axes. See example below). A no-arg constructor that creates a default rectangle with (0.0, 0.0) for (xpos, ypos) and 1.0 for both width and height. A constructor that creates a rectangle with the specified xpos, ypos, width, and height. Get and set methods for all the instance variables. A method getArea () that returns the area of the rectangle. A method getPerimeter () that returns the perimeter of the rectangle. A method contains (x, y) that returns true if the specified point (x, y) is inside this rectangle. See Figure 1(a). A method contains (Point p) that returns true if the specified Point (see Exercise 1) has coordinates inside the rectangle. (This is also similar to Figure 1(a).) A method contains (Rectangle2D r) that returns true if the specified rectangle is inside this rectangle. See Figure 1 (b). Note that the condition for contains is that all four corners of the second rectangle must be contained in the first. This means, that if the two rectangles are exactly identical, we still say that the second rectangle is contained within the other. Write a test program that creates a Rectangle2D object and tests various methods. For example, as a first test case, create a Rectangle2D object r1 with parameters 2, 2, 5.5 and 4.9, which represent xpos, ypos width and height, respectively, displays its area and perimeter, and displays the result of r1.contains (3, 3) and r1.contains (new Rectangle2D (4, 5, 10.5, 3.2)). Create a Point p using the coordinates 3, 3 and verify that r1.contains (p) returns the same (expected) value

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

Step: 3

blur-text-image

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

10.

Answered: 1 week ago

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago