Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is wrong with my code at the bottom (union and rec1) ALSO: could someone help me add the following method to the program: public

What is wrong with my code at the bottom (union and rec1)

ALSO: could someone help me add the following method to the program:

public rectangle intersection(rectangle rect)

Return a new rectangle that represents the largest rectangular region completely contained within both this rectangle and the given other rectangle. If the rectangles do not intersect at all, returns a rectangle with both with and height equal to 0.

HERE IS MY CODE:

import java.awt.Point;

public class rectangle {

private int x;

private int y;

private int width;

private int height;

private Point pm;

public rectangle(int x, int y, int width, int height){

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

throw new IllegalArgumentException();

}

this.x = x;

this.y = y;

this.width = width;

this.height = height;

}

public rectangle(Point p, int width, int height) {

this.pm = p;

this.width = width;

this.height = height;

}

public int getHeight(){

return this.height;

}

public int getWidth(){

return this.width;

}

public int getX(){

return this.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){

int 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;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

=+4. About the medium.

Answered: 1 week ago

Question

107 MA ammeter 56 resistor ? V voltmeter

Answered: 1 week ago

Question

Generally If Drug A is an inducer of Drug B , Drug B levels will

Answered: 1 week ago

Question

3. Provide advice on how to help a plateaued employee.

Answered: 1 week ago