• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

advictoriam Jan 25th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /**
2.    A rectangle with height and width.
3. */
4. public class Rectangle
5. {
6.    private int height;
7.    private int width;
8.
9.    /**
10.       Constructs a rectangle.
11.       @param aHeight: the height of the rectangle
12.       @param aWidth: the width of the rectangle
13.    */
14.    public Rectangle(int aHeight, int aWidth)
15.    {
16.       height = aHeight;
17.       width = aWidth;
18.    }
19.
20.    /**
21.       Constructs a rectangle that is a square.
22.       @param aSide: the length of a side of the square
23.    */
24.    public Rectangle(int aSide)
25.    {
26.       height = aSide;
27.       width = aSide;
28.    }
29.
30.    /**
31.       Computes the perimeter.
32.       @return the perimeter of the rectangle
33.    */
34.    public int perimeter()
35.    {
36.       return 2 * height + 2 * width;
37.    }
38.
39.    /**
40.       Computes the area.
41.       @return the area of the rectangle
42.    */
43.    public int area()
44.    {
45.       return height * width;
46.    }
47.
48.    // This method is used for checking your work. Do not modify it
49.
50.    public static String check(int h, int w, int sideSq)
51.    {
52.       Rectangle aRect = new Rectangle(h, w);
53.       Rectangle aSquare = new Rectangle(sideSq);
54.       return aRect.perimeter() + " " + aRect.area() + " "
55.            + aSquare.perimeter() + " " + aSquare.area();
56.    }
57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top