ITEC 120 LAB 10 Back to Lab index page

A Point

Write a class to represent a point (x, y) where x and y are integers.

Point

- x : int
- y : int

+ Point(x:int, y:int)
+ distanceFromOrigin() : double
+ toString() : String

Write a driver which instantiates two points and print them out. Also display the distanceFromOrigin for each point.

Sample run:

Program displays: Point One: ( 3, 4 ), Point Two: ( 5, 13 )
Distance of point one from origin: 5.0
Distance of point two from origin: 13.92838827718412
Distance of point one from point two: 9.219544457292887

LAB CHALLENGE - for those who have checked off the lab -- if you finish the challenge, show the Peer Instructor for an extra credit point. (PIs, put a plus (+) next to the check for this lab.)

Write a method

public double distance (Point b)

which returns the distance between this point and point b

Test this method in your driver.