Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Rectangle
- {
- //attributes must be private
- private double length, width;
- //default constructor
- public Rectangle()
- {
- //assign default values to attributes
- length = 1;
- width = 1;
- }
- //parameterized constructor
- public Rectangle(double len, double wid)
- {
- //assign parameter values to attributes
- length = len;
- width = wid;
- }
- //sets and gets for length and width
- public void setLength(double len)
- {
- length = len;
- }
- public double getLength()
- {
- return length;
- }
- public void setWidth(double wid)
- {
- width = wid;
- }
- public double getWidth()
- {
- return width;
- }
- //area is calculated, only needs get
- public double getArea()
- {
- return length * width;
- }
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement