sad-ronin-v

LINE

Oct 8th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. public class Line {
  2.     private Point A;
  3.     private Point B;
  4.  
  5.     public Line() {
  6.         A=new Point(0, 0);
  7.         B=new Point(0, 1);
  8.     }
  9.  
  10.     public Line(Point A, Point B) {
  11.         this.A = A;
  12.         this.B = B;
  13.     }
  14.     public Line(double x1,double x2, double y1, double y2){
  15.         this.A=new Point(x1,y1);
  16.         this.B=new Point(x2,y2);
  17.     }
  18.     public double getLength(){
  19.         double dx=Math.abs(A.getX()-B.getX());
  20.         double dy=Math.abs(A.getY()-B.getY());
  21.         return Math.sqrt(dx*dx+dy*dy);
  22.     }
  23.    
  24.     public double getDiagonal(){
  25.         return Math.sqrt(2)*getLength();
  26.        
  27.     }
  28.     public double getPerimeter(){
  29.         return 4*getLength();
  30.     }
  31.     public double getSquare(){
  32.        
  33.         return Math.pow(getLength(),2);
  34.     }
  35.    
  36.    
  37.     public Point getA() {
  38.         return A;
  39.     }
  40.  
  41.     public Point getB() {
  42.         return B;
  43.     }
  44.  
  45.     public void setA(Point A) {
  46.         this.A = A;
  47.     }
  48.  
  49.     public void setB(Point B) {
  50.         this.B = B;
  51.     }
  52.     @Override
  53.     public String toString(){
  54.         return "Line(point A("+A.getX()+","+A.getY()+"); point B("+B.getX()+","+B.getY()+")";
  55.     }
  56.    
  57.    
  58.    
  59. }
Add Comment
Please, Sign In to add comment