Advertisement
PadmaJS

Rectangle

Sep 30th, 2022
2,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.92 KB | None | 0 0
  1. //TestRectangle.java
  2. public class TestRectangle {
  3.   public static void main(String[] args) {
  4.     Rectangle rectangle1 = new Rectangle();
  5.     Rectangle rectangle2 = new Rectangle(4, 5.5);
  6.     System.out.println("Width: " + rectangle1.width + "\nHeight: " + rectangle1.height + "\nArea: "
  7.         + rectangle1.getArea() + "\nPerimeter: " + rectangle1.getPerimeter());
  8.     System.out.println("Width: " + rectangle2.width + "\nHeight: " + rectangle2.height + "\nArea: "
  9.         + rectangle2.getArea() + "\nPerimeter: " + rectangle2.getPerimeter());
  10.   }
  11. }
  12.  
  13. //Rectangle.java
  14. public class Rectangle {
  15.   double width = 1;
  16.   double height = 1;
  17.  
  18.   public Rectangle() {
  19.   }
  20.  
  21.   public Rectangle(double height, double width) {
  22.     this.width = width;
  23.     this.height = height;
  24.   }
  25.  
  26.   public double getArea() {
  27.     return (width * height);
  28.   }
  29.  
  30.   public double getPerimeter() {
  31.     return (2 * (width + height));
  32.   }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement