Advertisement
SirBaconBitz

classRectangle

Dec 19th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. public class Rectangle {
  2.  
  3.     int x, y, width, height;
  4.    
  5.     public Rectangle(int x, int y, int width, int height) throws IllegalArgumentException {
  6.         if (width < 0 || height < 0) throw new IllegalArgumentException();
  7.         this.x = x;
  8.         this.y = y;
  9.         this.width = width;
  10.         this.height = height;
  11.     }
  12.    
  13.     public int getHeight() {
  14.         return height;
  15.     }
  16.    
  17.     public int getWidth() {
  18.         return width;
  19.     }
  20.    
  21.     public int getX() {
  22.         return x;
  23.     }
  24.    
  25.     public int getY() {
  26.         return y;
  27.     }
  28.    
  29.     public String toString() {
  30.         return String.format("Rectangle[x=%d,y=%d,width=%d,height=%d]", x, y, width, height);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement