CSC1110 - Week 7 Exercise

Instructions

Implement the following classes based on their UML and descriptions. At the end, are the sample outputs from two separate runs.

Point

Point
-x:double
-y:double
+Point(x:double,y:double)
+getX():double
+getY():double

This class represent a Point is 2D space that posses an (x,y) value.

Rectangle

Rectangle
-upperLeft:Point
-x:double
-y:double
+Rectangle(width:double, height:double, x:double, y:double)
+hit(testPoint: Point):boolean
+display():void
-getLowerRightCorner():Point

This class represents a Rectangle that has a width and height, but also a Point that represents the location of the upper left-hand corner. The hit() method returns true if the passed-in x and y values passed in, fall within the perimeter of the Rectangle. The display() method prints out "Rectangle", and then the x and y of the upper left-hand corner and the width and height. See the sample output.

RectangleDriver

RectangleDriver

+main(args:String[])
-makeRectangle(scan:Scanner):Rectangle
-checkPoint(rec:Rectangle, scan:Scanner):void

This is the driver class and contains a main() and two helper methods.

Sample Output

Enter the width: 3
Enter the height: 4
Enter the x of the top left corner: 0
Enter the y of the top left corner: 0
Rectangle: 
x:0.0,y:0.0
Width:3.0,Height:4.0
Enter the x of the Point you want to test: 1
Enter the y of the Point you want to test: 1
This point (1.0,1.0) is within the Rectangle
Enter the width: 3
Enter the height: 4
Enter the x of the top left corner: 2
Enter the y of the top left corner: 2
Rectangle: 
x:2.0,y:2.0
Width:3.0,Height:4.0
Enter the x of the Point you want to test: 1
Enter the y of the Point you want to test: 1
This point (1.0,1.0) is not within the Rectangle

Submission

See your professor's instructions for details on submission guidelines and due dates.