Created
June 15, 2012 13:50
-
-
Save rslima/2936568 to your computer and use it in GitHub Desktop.
Squares and Rectangles in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Rectangle { | |
private final int h; | |
private final int w; | |
public Rectangle(int height, int width) { | |
h = height; | |
w = width; | |
} | |
public int getH() { | |
return h; | |
} | |
public int getW() { | |
return w; | |
} | |
public Rectangle setH(int height) { | |
return new Rectangle(height,w); | |
} | |
public Rectangle setW(int width) { | |
return new Rectangle(h,width); | |
} | |
public int perimeter() { | |
return 2 * (h + w); | |
} | |
public int area() { | |
return h * w; | |
} | |
} | |
public class Square extends Rectangle { | |
public Square(int side) { | |
super(side,side); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment