This is the original one:
Quote:
class TestPoint
{
public static void main (String[] args)
{
Point p1 = new Point ();
Point p2 = new Point ();
Point p3 = new Point ();
Point p4 = new Point ();
p1.setx (2);
p1.sety (4);
p2.setx (3);
p2.sety (5);
p3.setx (9);
p3.sety (7);
p4.setx (6);
p4.sety (2);
System.out.println ("Point1(" + p1.getx () + ", " + p1.gety () + ")");
System.out.println ("Point2(" + p2.getx () + ", " + p2.gety () + ")");
System.out.println ("Point3(" + p3.getx () + ", " + p3.gety () + ")");
System.out.println ("Point4(" + p4.getx () + ", " + p4.gety () + ")");
System.out.println (" ");
p2.add (p3);
System.out.println ("p2 + p3 = (x, y)");
System.out.println ("(" + p2.getx () + ", " + p2.gety () + ")");
System.out.println (" ");
System.out.println ("p4 + p1 = (x, y)");
System.out.println ("(" + (p4.getx () + p1.getx ()) + ", " + (p4.gety () + p1.gety ()) + ")");
System.out.println (" ");
p2.subtract (p1);
System.out.println("p2 - p1 = (x, y)");
System.out.println("("+ (p2.getx() - p1.getx()) +", "+ (p2.gety() - p1.gety()) +")");
System.out.println(" ");
p1.dist (p2);
System.out.println ("Distance between p1 and p2 is: " + p1.dist (p2));
System.out.println ("Distance between p2 and p3 is: " + p2.dist (p3));
System.out.println ("Distance between p3 and p4 is: " + p3.dist (p4));
System.out.println ("Distance between p3 and p1 is: " + p3.dist (p1));
}
}
Quote:
class Point
{
int x;
int y;
void setx (int x)
{
this.x = x;
}
void sety (int y)
{
this.y = y;
}
int getx ()
{
return this.x;
}
int gety ()
{
return this.y;
}
void add (Point p)
{
x = x + p.x;
y = y + p.y;
}
void subtract (Point p)
{
x = x - p.x;
y = y - p.y;
}
double dist (Point p)
{
return Math.sqrt ((Math.pow ((x - p.x), 2) + Math.pow ((y - p.y), 2)));
}
}
Im trying to make it as an input way but i cant.
Quote:
import java.io.*;
class TestPoint
{
public static void main (String[] args) throws IOException
{
int rounds = 1;
String input;
Point p1 = new Point ();
Point p2 = new Point ();
Point p3 = new Point ();
Point p4 = new Point ();
BufferedReader stdin = new BufferedReader (
new InputStreamReader (System.in));
for (int i = 1 ; i <= 5 ; i++)
{
System.out.println ("Enter x: ");
input = stdin.readLine ();
p1.setx = new Point ();
System.out.println ("Enter y: ");
input = stdin.readLine ();
p1.sety = new Point ();
}
p2.setx (1);
p2.sety (5);
p3.setx (1);
p3.sety (2);
p4.setx (-2);
p4.sety (1);
System.out.println ("Point1(" + p1.getx () + ", " + p1.gety () + ")");
System.out.println ("Point2(" + p2.getx () + ", " + p2.gety () + ")");
System.out.println ("Point3(" + p3.getx () + ", " + p3.gety () + ")");
System.out.println ("Point4(" + p4.getx () + ", " + p4.gety () + ")");
System.out.println (" ");
p2.add (p3);
System.out.println ("p2 + p3 = (x, y)");
System.out.println ("(" + p2.getx () + ", " + p2.gety () + ")");
System.out.println (" ");
System.out.println ("p4 + p1 = (x, y)");
System.out.println ("(" + (p4.getx () + p1.getx ()) + ", " + (p4.gety () + p1.gety ()) + ")");
System.out.println (" ");
p2.subtract (p1);
System.out.println ("p2 - p1 = (x, y)");
System.out.println ("(" + (p2.getx () - p1.getx ()) + ", " + (p2.gety () - p1.gety ()) + ")");
p1.dist (p2);
System.out.println ("Distance between p1 and p2 is: " + p1.dist (p2));
System.out.println ("Distance between p2 and p3 is: " + p2.dist (p3));
System.out.println ("Distance between p3 and p4 is: " + p3.dist (p4));
System.out.println ("Distance between p3 and p1 is: " + p3.dist (p1));
}
}