Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rectangle
- {
- //declares instance variables
- private int length;
- private int width;
- /**
- * Rectangle
- * sets the length and width to default values
- * pre: none
- * post: length and with set = to 1
- */
- public void Rectangle()
- {
- // sets length and width as 1 if no parameters are entered
- length = 1;
- width = 1;
- }
- /**
- * Rectangle
- * sets the length and width to values entered by user
- * pre: none
- * post: length and width set = to user input
- */
- public void Rectangle ( int len, int wid)
- {
- //sets the legth and width as the user variable
- length = len;
- width = wid;
- }
- //rectangle object with default numbers
- Rectangle rectan1= new Rectangle();
- System.out.println("Area of rectangle with no parameters: "+
- rectan1.area());
- //rectangle object using parameters
- Rectangle rectan2= new Rectangle(2,3); //ERROR RECEIVED HERE
- System.out.println("Perimeter of rectangle with parameters: "+
- rectan2.perimeter());
Add Comment
Please, Sign In to add comment