Advertisement
mmayoub

RunRectangle, 26.06.2021

Jun 26th, 2021
1,143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1.  
  2. public class RunRectangle {
  3.     public static void main(String[] args) {
  4.  
  5.         Rectangle r1 = new Rectangle(3, 3);
  6.         System.out.println(r1); // toString()
  7.         Rectangle r2 = new Rectangle(7, 10);
  8.         System.out.println(r2);
  9.  
  10.         // Test setters and getters
  11.         r1.setLength(5.6);
  12.         r1.setWidth(7.8);
  13.         System.out.println(r1); // toString()
  14.         System.out.println("length is: " + r1.getLength());
  15.         System.out.println("width is: " + r1.getWidth());
  16.  
  17.         // Test getArea() and getPerimeter()
  18.         System.out.printf("area is: %f", r1.getArea());
  19.         System.out.printf("perimeter is: %f", r1.getPerimeter());
  20.  
  21.     }
  22.  
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement