Hey.
I have this assignment but i have no idea of how to fix a part of it and i have been stuck on it for a while.
Any ideas? I get stuck at p1 and p2. I can print them but they want me to get them thru the toStrings.
I think that i can handle the rest. I just need to know of how i can make a method that returns the values and
so that i can use those by the "toStrings".
Any ideas?
Create a class Point that when executed using this code:
Point p1 = new Point(); //These once right here!!!
Point p2 = new Point(3,4);
System.out.println(p1.toString()); // ==> (0,0)
System.out.println(p2.toString()); // ==> (3,4)
if (p1.isEqualTo(p2)) // False!
System.out.println("The two points are equal");
double dist = p1.distanceTo(p2);
System.out.println("Point Distance: "+dist);
p2.move(5,-2); // ==> (8,2)
p1.moveToXY(8,2); // ==> (8,2)
if (p1.isEqualTo(p2)) // True!
System.out.println("The two points are equal");
results in the following console print-out:
(0,0)
(3,4)
Point Distance: 5.0
The two points are equal
The class Point should of course be able to handle other points with different (x,y) values. Notice:
The coordinates (x,y) are always integers.
The method toString returns a string with coordinates suitable for print-outs.
Distance between two points is computed in the same way as in Exercise 15, Assignment 1.
Two points are equal if they have the same coordinates.
Method move moves the point certain steps in x- and y-direction.
Method moveToXY provide a new set of coordinates.