Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Question Use the following UML diagram to define a class called Point and Rectangle, where a Rectangle is aggregated from 4 Point objects. A

Java Question

Use the following UML diagram to define a class called Point and Rectangle, where a Rectangle is aggregated from 4 Point objects. A Point has an x and y coordinate and a Rectangle has 4 Points that represent the upper left, upper right, lower left and lower right.

image text in transcribedimage text in transcribed

Notes

  • To determine if one Point is higher than other, compare the y values
  • To determine if one Point is further than other, compare the x values
  • A Rectangle contains a Points if the point lies inside the Rectangle (not on the edges)
  • A Rectangle contains a Rectangle if the other Rectangle fits inside this Rectangle (with no Points on the edges) (see below).
  • A Rectangle overlaps another Rectangle if one or two points of one Rectangle are contained in another Rectangle (see below).
  • A Rectangle crosses another Rectangle if two Rectangles overlap on 2 edges but do not contain any Points inside (see below).

image text in transcribed

Details

Now create a RectangleDemo to create and use Rectangle objects. Use a Scanner object to read the attributes for four Rectangle objects (4 Points per Rectangle).

In the demo: Print the four Rectangles (using the toString method). Print the width, height and area of the first Rectangle. Print if the first Rectangle object is higher than the second Rectangle object Print if the first Rectangle object contains the second Rectangle object Print if the second Rectangle object contains the third Rectangle object Print if the first and third Rectangle cross over each other Print if the first Rectangle overlaps the second Rectangle Print if the forth Rectangle overlaps the first Rectangle

Input

4 points per 4 Rectangles (2 * 4 * 4 numbers) Sample Input: 2 7 2 2 8 7 8 2 4 6 4 4 6 6 6 4 3 8 3 1 5 8 5 1 6 3 6 1 10 3 10 1

Output

Sample Output: Rectangle: (2, 7) (8, 7) (2, 2) (8, 2) Rectangle: (4, 6) (6, 6) (4, 4) (6, 4) Rectangle: (3, 8) (5, 8) (3, 1) (5, 1) Rectangle: (6, 3) (10, 3) (6, 1) (10, 1) R1 width: 6 R1 height: 5 R1 area: 30 r1 is higher than r2 is true r1 contains r2 is true r2 contains r3 is false r1 and r3 cross is true r1 overlaps r2 is false r4 overlaps r1 is true

Rectangle upperL: Point lowerL: Point upperR: Point lowerR: Point +Rectangle (ul: Point, Il: Point, ur: Point, Ir: Point): getUpperL(): Point +getLowerL ( Point getUpperR(): Point +getLowerR(): Point +setUpperL(p: Point): void +setLowerL(p: Point): void +setUpperR(p: Point): void +setLowerR(p: Point): void + width (): int + height(): int +area (): int +equals (r: Rectangle): boolean +contains (p: Point): boolean +contains (r: Rectangle): boolean +overlaps (r: Rectangle): boolean +crosses (r: Rectangle): boolean +toString(): String Point xPos: int yPos: int Point (: + Point (x:int, y int) +getXPos ): int + getYPos(): int + setXPos (x: int): void +setYPos (y:int): voiod equals (p: Point): boolean + isHigher (p: Point): boolean +isFurther (p: Point): boolean +toString): String Different scenarios: contains(Rectangle) crosses(Rectangle) overlaps(Rectangle) overlaps(Rectangle) Rectangle upperL: Point lowerL: Point upperR: Point lowerR: Point +Rectangle (ul: Point, Il: Point, ur: Point, Ir: Point): getUpperL(): Point +getLowerL ( Point getUpperR(): Point +getLowerR(): Point +setUpperL(p: Point): void +setLowerL(p: Point): void +setUpperR(p: Point): void +setLowerR(p: Point): void + width (): int + height(): int +area (): int +equals (r: Rectangle): boolean +contains (p: Point): boolean +contains (r: Rectangle): boolean +overlaps (r: Rectangle): boolean +crosses (r: Rectangle): boolean +toString(): String Point xPos: int yPos: int Point (: + Point (x:int, y int) +getXPos ): int + getYPos(): int + setXPos (x: int): void +setYPos (y:int): voiod equals (p: Point): boolean + isHigher (p: Point): boolean +isFurther (p: Point): boolean +toString): String Different scenarios: contains(Rectangle) crosses(Rectangle) overlaps(Rectangle) overlaps(Rectangle)

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

Students also viewed these Databases questions