RazorBlade57

Distance

Oct 21st, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. //© A+ Computer Science  -  www.apluscompsci.com
  2. //Name -
  3. //Date -
  4. //Class -
  5. //Lab  -
  6.  
  7. import java.util.Scanner;
  8. import static java.lang.System.*;
  9. import static java.lang.Math.*;
  10.  
  11. public class Distance
  12. {
  13.     private int xOne,yOne,xTwo,yTwo;
  14.     private double distance;
  15.  
  16.     public Distance()
  17.     {
  18.         xOne = 0;
  19.         xTwo = 0;
  20.         yOne = 0;
  21.         yTwo = 0;
  22.     }
  23.  
  24.     public Distance(int x1, int y1, int x2, int y2)
  25.     {
  26.         xOne = x1;
  27.         xTwo = x2;
  28.         yOne = y1;
  29.         yTwo = y2;
  30.         }
  31.  
  32.     public void setCoordinates(int x1, int y1, int x2, int y2)
  33.     {
  34.        
  35.         xOne = x1;
  36.         xTwo = x2;
  37.         yOne = y1;
  38.         yTwo = y2;
  39.        
  40.         }
  41.  
  42.     public void calcDistance()
  43.     {
  44.  
  45.         distance = Math.sqrt(Math.pow(xTwo - xOne, 2) + Math.pow(yTwo - yTwo, 2));
  46.  
  47.     }
  48.  
  49.     public void print( )
  50.     {
  51.  
  52.         System.out.println(distance);
  53.  
  54.     }
  55. }
Add Comment
Please, Sign In to add comment