Guest User

Untitled

a guest
Jul 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. public class Room {
  2.     //length of room object
  3.     private double length;
  4.     //width of room object
  5.     private double width;
  6.    
  7.     public Room (double length, double width) {
  8.         //this objects length data member gets
  9.         //the value in the length param
  10.         setLength(length);
  11.         //this objects width data member gets
  12.         //the value in the width param
  13.         setWidth(width);
  14.     }
  15.     public Room (){}
  16.    
  17.     public void setLength (double length) {
  18.         if (length > 0) {
  19.             this.length = length;
  20.         }
  21.     }
  22.     public double getLength() { return length; }
  23.     public void setWidth(double width) {
  24.         if (width > 0) {
  25.             this.width = width;
  26.         }
  27.     }
  28.     public double getWidth() { return width; }
  29.     public double calcArea() {
  30.         //return area as length * width
  31.         return length * width;
  32.     }
  33.     public void displayRoom() {
  34.         System.out.printf("%.1f x %.1f%n", length, width);
  35.     }
  36. }
Add Comment
Please, Sign In to add comment