Question: Java public class ThePoint { //fields private double xCoordinate ; private double yCoordinate ; // default constructor public ThePoint() { this.xCoordinate = 0 ; this.yCoordinate
Java

public class ThePoint { //fields private double xCoordinate ; private double yCoordinate ; // default constructor public ThePoint() { this.xCoordinate = 0 ; this.yCoordinate = 0 ; } //parameterized constructor public ThePoint(double xCoordinate, double yCoordinate) { this.xCoordinate = xCoordinate; this.yCoordinate = yCoordinate; } //setters and getters public double getxCoordinate() { return xCoordinate; } public void setxCoordinate(double xCoordinate) { this.xCoordinate = xCoordinate; } public double getyCoordinate() { return yCoordinate; } public void setyCoordinate(double yCoordinate) { this.yCoordinate = yCoordinate; } public double distance() { return Math.sqrt(Math.pow(this.xCoordinate, 2) + Math.pow(this.yCoordinate, 2)); } public double distance(double x, double y) { return Math.sqrt(Math.pow(this.xCoordinate-x, 2) + Math.pow(this.yCoordinate-y, 2)); } public double distance(ThePoint point) { return Math.sqrt(Math.pow(this.xCoordinate-point.getxCoordinate(), 2) + Math.pow(this.yCoordinate-point.getyCoordinate(), 2)); } public String toString() { return "[" + xCoordinate + ", " + yCoordinate + "]"; } }
a. Design and implement a class called TheRectangle that models a rectangle with its top-left and bottom- right corners points. The TheRectangle class uses two instances of ThePoint class (created in the previous exercise) as its top-left and bottom-right corners points. TheRectangle should contains essential attributes, the basic set of methods b. a constructor that constructs a rectangle with the given its top-left and bottomright corners (tlx, tly, brx, bry) an overloaded constructor that constructs a rectangle with two ThePoint instances a method that calculates the area of the rectangle, a method that calculates distance of the top-left corner from the given TheRectangle instance's top-left corner f. the number of rectangles that are created during the run-time Write a test program that test all the methods defined in the class. C. d. e
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
