Question: Please use Java to finish the code, thank! This is similar to the exercise that was discussed in the lectures. However, you need to define

 Please use Java to finish the code, thank! This is similar

Please use Java to finish the code, thank!

This is similar to the exercise that was discussed in the lectures. However, you need to define two methods, namely, contains and touches, that have slightly different meanings. Please see the diagrams. Define the Rectangle class that contains: Double data fields named xpos, ypos (that specify the top left corner of the rectangle), width and height. (assume that the rectangle sides are parallel to the x and y axes. See example below). 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 contains(Rectangle r) that returns true if the specified rectangle is inside this rectangle. A method touches(Rectangle r) that returns true if the specified rectangle touches this rectangle. You may add other methods if necessary. Study the figures to understand when the contains method should return true, and when the touches method should return true. If the rectangles overlap, both methods should return false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!