Monty374

Rectangle 2

Nov 2nd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public class Rectangle {
  2. private int length, width;
  3.  
  4. public Rectangle() {
  5. length = 2;
  6. width = 1;
  7. }
  8.  
  9. public void Rectangle(int l, int w) {
  10. length = l;
  11. width = w;
  12.  
  13. }
  14.  
  15. public int perimeter() {
  16. int perimeter;
  17. perimeter = 2 * length + 2 * width;
  18. return(perimeter);
  19. }
  20.  
  21. public int area() {
  22. int area;
  23. area = length * width;
  24. return(area);
  25. }
  26.  
  27. public static void formula(){
  28. System.out.println("Area formula: a = l * w");
  29. }
  30.  
  31. public static void main(String[] args) {
  32. Rectangle box = new Rectangle();
  33.  
  34. System.out.println("Perimeter: " + box.perimeter());
  35. System.out.println("Area: " + box.area());
  36. Rectangle.formula();
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment