Next page | Contents page |

Exercise 8 - Point

Define a class called Point which has two integer data values for its coordinates: x and y. Write get and set methods for these, plus a suitable constructor for a Point object.

Also write a method to get the distance of the point from (0, 0). This takes no parameters but returns a floating point result. Write an application which outputs this distance when x and y values are given as command parameters. What would be suitable test inputs (remember Pythagoras)?

Hint: The distance is given by the square root of the sum of the squares of x and y. You will need to use the API documentation to find a square root function (there are 2 - use the less strict one).

Then go on to write another method which gets the distance of one Point from another one.

Next page | Contents page |