Guest User

Untitled

a guest
Oct 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. package Rectangle;
  2. //business layer
  3.  
  4. public class Rectangle
  5. {
  6. //hard code instance variables
  7. //Encapsulation
  8. private int length;
  9. private int width;
  10.  
  11. //create a constructor
  12. public Rectangle(int length, int width)
  13. {
  14. length = 0;
  15. width = 0;
  16. }
  17.  
  18. //the setter and getter for the instance variables
  19.  
  20. public void setLength(int length)
  21. {
  22. this.length = length;
  23. }
  24.  
  25. public int getLength()
  26. {
  27. return length;
  28. }
  29.  
  30. public void setWidth(int width)
  31. {
  32. this.width = width;
  33. }
  34.  
  35. public int getWidth()
  36. {
  37. return width;
  38. }
  39.  
  40. //are and permieter
  41. public int area()
  42. {
  43. return length * width;
  44. }
  45.  
  46. public int per()
  47. {
  48. return (length + width) * 2;
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment