Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- A rectangle with height and width.
- */
- public class Rectangle
- {
- private int height;
- private int width;
- /**
- Constructs a rectangle.
- @param aHeight: the height of the rectangle
- @param aWidth: the width of the rectangle
- */
- public Rectangle(int aHeight, int aWidth)
- {
- height = aHeight;
- width = aWidth;
- }
- /**
- Constructs a rectangle that is a square.
- @param aSide: the length of a side of the square
- */
- public Rectangle(int aSide)
- {
- height = aSide;
- width = aSide;
- }
- /**
- Computes the perimeter.
- @return the perimeter of the rectangle
- */
- public int perimeter()
- {
- return 2 * height + 2 * width;
- }
- /**
- Computes the area.
- @return the area of the rectangle
- */
- public int area()
- {
- return height * width;
- }
- // This method is used for checking your work. Do not modify it
- public static String check(int h, int w, int sideSq)
- {
- Rectangle aRect = new Rectangle(h, w);
- Rectangle aSquare = new Rectangle(sideSq);
- return aRect.perimeter() + " " + aRect.area() + " "
- + aSquare.perimeter() + " " + aSquare.area();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement