Yuvalxp8

Exercise 20 Page 46

Feb 8th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Point
  4. {
  5. private int x;
  6. private int y;
  7.     public Point(int x, int y)
  8.     {
  9.     this.setX(x);
  10.     this.setY(y);
  11.     }
  12.     public double getX()
  13.     {
  14.         return x;
  15.     }
  16.     public void setX(int x)
  17.     {
  18.         this.x = x;
  19.     }
  20.     public double getY()
  21.     {
  22.         return y;
  23.     }
  24.     public void setY(int y)
  25.     {
  26.         this.y = y;
  27.     }
  28.     public String tior()
  29.     {
  30.         return "x= " + this.x + "\n" + "y= " + this.y;
  31.     }
  32. /////////////////////////////////////////////////////////
  33.     static Scanner in = new Scanner(System.in);
  34.     public static void main (String []args)
  35.     {
  36.         System.out.println("Enter two coordination sets (x y ,x y)");
  37.     Point p1 = new Point(in.nextInt(),in.nextInt());
  38.     Point p2 = new Point(in.nextInt(),in.nextInt());
  39.     System.out.println("Point #1: " + "\n" + p1.tior() + "\n" + "Point #2 " + "\n" + p2.tior());
  40.    
  41.     if (p1.getX() == p2.getX() && p1.getY() == p2.getY())
  42.     {
  43.         System.out.println("Both points are exactly equal");
  44.         return;
  45.     }
  46.    
  47.     if (p1.getY() == p2.getY())
  48.     {
  49.         System.out.println("Both points are on the exact same Y axis");
  50.         return;
  51.     }
  52.  
  53.     if (p1.getX() == p2.getX())
  54.     {
  55.         System.out.println("Both points are on the exact same X axis");
  56.         return;
  57.     }
  58.    
  59.     if (p1.getX() != p2.getX() && p1.getY() != p2.getY())
  60.     {
  61.         System.out.println("Both points have no connection");
  62.         return;
  63.     }
  64.     }
  65.    
  66.    
  67.    
  68. }
Add Comment
Please, Sign In to add comment