Question: Could someone make a main class to test out my class methods? import java.awt.Point; public class Rectangle { private int x; private int y; private

Could someone make a main class to test out my class methods?

import java.awt.Point;

public class Rectangle {

private int x;

private int y;

private double width;

private double height;

private Point pm;

public Rectangle(int x, int y, double width,double height){

if(width < 0 || height < 0){

throw new IllegalArgumentException();

}

pm.x = x;

pm.y = y;

this.width = width;

this.height = height;

}

public Rectangle(Point p, double width, double height) {

this.pm = p;

this.width = width;

this.height = height;

}

public double getHeight(){

return this.height;

}

public double getWidth(){

return this.width;

}

public int getX(){

return this.pm.x;

}

public int getY(){

return this.y;

}

public String toString(){

return "Rectangle[ X = " + x + ", Y = " + y + ", Width = " + width + ", Height = " + height + " ]";

}

public String toStringp(){

return "Rectangle[ X = " + pm.x + ", Y = " +pm.y + ", Width = " + width + ", Height = " + height + " ]";

}

public boolean contains(int x,int y){

if(x

return true;

else{

return false;

}

}

public boolean contains(Point p){

if(p.getX() < x && p.getY() < y){

return true;

}

else{

return false;

}

}

public Rectangle union(Rectangle rect){

double hei1, wid1;

hei1 = rect.getHeight() + (int)pm.getX();

wid1 = rect.getWidth() + (int)pm.getY();

Rectangle rec1 = new Rectangle((int)pm.getX(), (int)pm.getY(), hei1, wid1);

rec1.height = hei1;

rec1.width = wid1;

return rec1;

}

public Rectangle intersection(Rectangle rect){

double hei1, wid1;

hei1 = Math.abs(rect.getHeight() - (int)pm.getX());

wid1 = Math.abs(rect.getWidth() - (int)pm.getY());

Rectangle rec1 = new Rectangle((int)pm.getX(), (int)pm.getY(), hei1, wid1);

rec1.height = hei1;

rec1.width = wid1;

return rec1;

}

}

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!