Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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 falseStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started