Question: This lab was designed to reinforce programming concepts from Chapter 5. In this lab, you will practice: Design Classes .Create objects Invoke methods on objects

This lab was designed to reinforce programming concepts from Chapter 5. In this lab, you will practice: Design Classes .Create objects Invoke methods on objects Exercise# 1: MyRectangle2DClass the MyRectangle2D class that contains the following attributes Design Two data fields named X and y that specify the center of the rectangle with getter and setter methods. (Assume that the rectangle sides are parallel to x- or y axes.) The data fields width and height with getter and setter methods. . A no-arg constructor that creates a default rectangle with (0, 0) for (X, y) and 1 for both width and height. . A constructor that creates a rectangle with the specified x, y, width, and height The class also contains the following methods: (a) Methods getArea() and getPerimeter) to return the area and perimeter of the rectangle (b) Method toString) to print the rectangle object. (c) A method contains(double x, double y) that returns true if the specified point (x, y) is inside this rectangle. (d) A method contains(MyRectangle2D r) that returns true if the specified rectangle is inside this rectangle. Write a test program that prompts the user to enter the (x.y) coordinates, width and height of a rectangle, creates a rectangle object and displays its area and perimeter. The program also prompts the user to enter the (x.y) coordinates of a point and checks whether it is inside a rectangle. And finally, create a second rectangle and checks whether it is inside/overlaps with the first rectangle Sample Input/Output Enter the x, y coordinates, width, and height of the rectangle: 2 2 5.5 4.9 center(2.00, 2.0e), width: 5.50, height: 4.90 area: 26.95, perimeter: 20.80 Enter the x, y coordinates of a point: 3 3 The point is inside the rectangle Enter the x, y coordinates of a point: 8.5 9.3 The point is outside the rectangle Enter the x, y coordinates, width, and height of the second rectangle: 2 2 4.1 2.3 1/2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
