Advertisement
atanasovetr

Exercise3

Dec 14th, 2020
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.66 KB | None | 0 0
  1. //class Point
  2. public class Point {
  3.     private double x;
  4.     private double y;
  5.     private String name;
  6.  
  7.     public Point() {
  8.         this.x = 0;
  9.         this.y = 0;
  10.         this.name = "BlankName";
  11.     }
  12.     public Point(String name) {
  13.         this.name = name;
  14.     }
  15.  
  16.     public Point(double x, double y, String name) {
  17.         this.x = x;
  18.         this.y = y;
  19.         this.name = name;
  20.     }
  21.  
  22.     public double distance(Point point2){
  23.         double dis;
  24.         dis = Math.sqrt((point2.getX()-this.getX())*(point2.getX()-this.getX()) + (point2.getY()-this.getY())*(point2.getY()-this.getY()));
  25.         return dis;
  26.     }
  27.  
  28.     public double getX() {
  29.         return x;
  30.     }
  31.  
  32.     public void setX(double x) {
  33.         this.x = x;
  34.     }
  35.  
  36.     public double getY() {
  37.         return y;
  38.     }
  39.  
  40.     public void setY(double y) {
  41.         this.y = y;
  42.     }
  43.  
  44.     public String getName() {
  45.         return name;
  46.     }
  47.  
  48.     public void setName(String name) {
  49.         this.name = name;
  50.     }
  51. }
  52.  
  53.  
  54.  
  55. //class PointMain
  56. import java.util.Scanner;
  57.  
  58. public class PointMain {
  59.     public static void main(String[] args) {
  60.         Scanner scan = new Scanner(System.in);
  61.         String point1Input = scan.nextLine();
  62.         String point2Input = scan.nextLine();
  63.         String point3Input = scan.nextLine();
  64.  
  65.         String[] point1Coors = point1Input.split(",");
  66.         String[] point2Coors = point2Input.split(",");
  67.         String[] point3Coors = point3Input.split(",");
  68.  
  69.         Point point1 = new Point("Point1");
  70.         point1.setX(Double.parseDouble(point1Coors[0]));
  71.         point1.setY(Double.parseDouble(point1Coors[1]));
  72.         Point point2 = new Point("Point2");
  73.         point2.setX(Double.parseDouble(point2Coors[0]));
  74.         point2.setY(Double.parseDouble(point2Coors[1]));
  75.         Point point3 = new Point("Point3");
  76.         point3.setX(Double.parseDouble(point3Coors[0]));
  77.         point3.setY(Double.parseDouble(point3Coors[1]));
  78.  
  79.         double dist1and2 = point1.distance(point2);
  80.         double dist2and3 = point2.distance(point3);
  81.         double dist1and3 = point1.distance(point3);
  82.  
  83.         if(dist1and2 > dist2and3 && dist1and2 > dist1and3){
  84.             System.out.println(dist1and2);
  85.             System.out.println(point1.getName() + "and"  + point2.getName());
  86.         }
  87.         else if(dist2and3 > dist1and2 && dist2and3 > dist1and3){
  88.             System.out.println(dist2and3);
  89.             System.out.println(point2.getName()  + "and"  + point3.getName());
  90.         }
  91.         else{
  92.             System.out.println(dist1and3);
  93.             System.out.println(point1.getName() + "and" + point3.getName());
  94.         }
  95.  
  96.  
  97.  
  98.     }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement