uni-assignments

University programming assignments
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

Rectangle.java (954B)


      1 class Rectangle {
      2         private Point pts[];
      3 
      4         Rectangle() {
      5                 pts = new Point[4];
      6                 for (int i = 0; i < pts.length; i++)
      7                         pts[i] = new Point(0.0, 0.0);
      8         }
      9 
     10         Rectangle(Point[] p) {
     11                 pts = p;
     12         }
     13 
     14         public Point[] getpoints() {
     15                 return pts;
     16         }
     17 
     18         public double width() {
     19                 return Math.abs(pts[1].x - pts[0].x);
     20         }
     21 
     22         public double height() {
     23                 return Math.abs(pts[2].y - pts[1].y);
     24         }
     25 
     26         public void info() {
     27                 System.out.println("Top:    " + pts[0]);
     28                 System.out.println("Width:  " + width());
     29                 System.out.println("Height: " + height());
     30         }
     31 
     32         public void print() {
     33                 for (Point p : pts)
     34                         System.out.print(p.toString() + " ");
     35                 System.out.println();
     36         }
     37 }