Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Room {
- //length of room object
- private double length;
- //width of room object
- private double width;
- public Room (double length, double width) {
- //this objects length data member gets
- //the value in the length param
- setLength(length);
- //this objects width data member gets
- //the value in the width param
- setWidth(width);
- }
- public Room (){}
- public void setLength (double length) {
- if (length > 0) {
- this.length = length;
- }
- }
- public double getLength() { return length; }
- public void setWidth(double width) {
- if (width > 0) {
- this.width = width;
- }
- }
- public double getWidth() { return width; }
- public double calcArea() {
- //return area as length * width
- return length * width;
- }
- public void displayRoom() {
- System.out.printf("%.1f x %.1f%n", length, width);
- }
- }
Add Comment
Please, Sign In to add comment