Guest User

Untitled

a guest
Jan 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public class Rectangle
  2. {
  3. //declares instance variables
  4. private int length;
  5. private int width;
  6.  
  7.  
  8. /**
  9. * Rectangle
  10. * sets the length and width to default values
  11. * pre: none
  12. * post: length and with set = to 1
  13. */
  14.  
  15. public void Rectangle()
  16. {
  17. // sets length and width as 1 if no parameters are entered
  18. length = 1;
  19. width = 1;
  20. }
  21.  
  22. /**
  23. * Rectangle
  24. * sets the length and width to values entered by user
  25. * pre: none
  26. * post: length and width set = to user input
  27. */
  28. public void Rectangle ( int len, int wid)
  29. {
  30. //sets the legth and width as the user variable
  31.  
  32. length = len;
  33. width = wid;
  34. }
  35.  
  36. //rectangle object with default numbers
  37. Rectangle rectan1= new Rectangle();
  38. System.out.println("Area of rectangle with no parameters: "+
  39. rectan1.area());
  40.  
  41. //rectangle object using parameters
  42. Rectangle rectan2= new Rectangle(2,3); //ERROR RECEIVED HERE
  43. System.out.println("Perimeter of rectangle with parameters: "+
  44. rectan2.perimeter());
Add Comment
Please, Sign In to add comment