Guest User

Untitled

a guest
Feb 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import java.util.*;
  2. public class Rectangle {
  3. int length;
  4. int width;
  5.  
  6. Rectangle(){
  7. length = 1;
  8. width = 1;
  9. }
  10. Rectangle(int x, int y){
  11. if(x <= 0 || y <= 0){
  12. length = 1;
  13. width = 1;
  14. }
  15. else{
  16. length = x;
  17. width = y;
  18. }
  19. }
  20. public int perimeter(){
  21. return (2*getLength() + 2*getWidth());
  22. }
  23. public int area(){
  24. return getLength()*getWidth();
  25. }
  26. public int getLength(){
  27. return length;
  28. }
  29. public int getWidth(){
  30. return width;
  31. }
  32.  
  33. }
Add Comment
Please, Sign In to add comment