Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SimplePoint {
- private double x,y;
- public SimplePoint(double x1, double y1) {
- x = x1;
- y = y1;
- }
- public double getX() { return x; };
- public double getY() { return y; };
- public double distance(SimplePoint p) {
- return Math.sqrt( Math.pow(p.getX()-x,2) + Math.pow(p.getY()-y,2) );
- }
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- SimplePoint OriginPoint = new SimplePoint(0.0, 0.0);
- double distance1, distance2, distance3, distance4;
- System.out.println("Enter four pairs of x,y coordinates:");
- SimplePoint point1 = new SimplePoint(input.nextDouble(), input.nextDouble());
- SimplePoint point2 = new SimplePoint(input.nextDouble(), input.nextDouble());
- SimplePoint point3 = new SimplePoint(input.nextDouble(), input.nextDouble());
- SimplePoint point4 = new SimplePoint(input.nextDouble(), input.nextDouble());
- distance1 = point1.distance(OriginPoint);
- distance2 = point2.distance(OriginPoint);
- distance3 = point3.distance(OriginPoint);
- distance4 = point4.distance(OriginPoint);
- if (distance1 > distance2 && distance1 > distance3 && distance1 > distance4)
- {System.out.printf("The point that's furthest from 0.0,0.0 is " + point1.getX() + "," + point1.getY() + " with distance: %.2f.", point1.distance(OriginPoint));}
- else if (distance2 > distance1 && distance2 > distance3 && distance2 > distance4)
- {System.out.printf("The point that's furthest from 0.0,0.0 is " + point2.getX() + "," + point2.getY() + " with distance: %.2f.", point2.distance(OriginPoint));}
- else if (distance3 > distance1 && distance3 > distance2 && distance3 > distance4)
- {System.out.printf("The point that's furthest from 0.0,0.0 is " + point3.getX() + "," + point3.getY() + " with distance: %.2f.", point3.distance(OriginPoint));}
- else if (distance4 > distance1 && distance4 > distance3 && distance4 > distance2)
- {System.out.printf("The point that's furthest from 0.0,0.0 is " + point4.getX() + "," + point4.getY() + " with distance: %.2f.", point4.distance(OriginPoint));}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment