Kasper123

Rectangle

Sep 9th, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. public class Rectangle {
  2.     private double width;
  3.     private double height;
  4.     public Rectangle() {
  5.         this.width = 1;
  6.         this.height = 1;
  7.     }
  8.     public Rectangle(double width, double height) {
  9.         this.width = width;
  10.         this.height = height;
  11.     }
  12.     public double getArea() {
  13.         return width * height;
  14.     }
  15.     public double getPerimeter() {
  16.         return 2 * (width + height);
  17.     }
  18.     public double getWidth() {
  19.         return width;
  20.     }
  21.     public double getHeight() {
  22.         return height;
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment