Delta_Sierra

Rectangle

Sep 11th, 2025
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         Rectangle myRectangle = new Rectangle();
  4.        
  5.         myRectangle.length = 5.00;
  6.         myRectangle.width = 10.00;
  7.         System.out.println("Action: Invoking getArea() method of the Rectangle");
  8.         System.out.print("Output: ");
  9.         System.out.println(myRectangle.getArea());
  10.         System.out.println();
  11.        
  12.         myRectangle.length = 3.00;
  13.         myRectangle.width = 4.00;
  14.         System.out.println("Action: Invoking getArea() method of the Rectangle");
  15.         System.out.print("Output: ");
  16.         System.out.println(myRectangle.getArea());
  17.         System.out.println();
  18.        
  19.         myRectangle.length = 2.50;
  20.         myRectangle.width = 4.50;
  21.         System.out.println("Action: Invoking getArea() method of the Rectangle");
  22.         System.out.print("Output: ");
  23.         System.out.println(myRectangle.getArea());
  24.     }
  25. }
  26. class Rectangle {
  27.    
  28.     public double length;
  29.     public double width;
  30.    
  31.     public double getArea() {
  32.         return length * width;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment