logo Practice-It logo

Office

Author: Allison Obourn (on 2012/08/29)

Define a class called Office that keeps track of information about an office's features. The class should have the following public methods:

Method Description
public Office(double width, double length, boolean couch, int windows) constructs an Office object with the given width and length, couch (true or false) and number of windows
public boolean isCorner() returns true if the office is a corner office. A corner office is square (has the same width and length) and has exactly two windows.
public String toString() returns a string representing the office in the format: width: , length: , windows: . If the office has a couch ", has a couch" should be appended to the end of the string.

Examples:

Office o1 = new Office (10.3, 10.3, true, 3);
Office o2 = new Office (14.0, 6.7, false, 3);

A call on o1.toString() and o2.toString() would return, respectively:

width: 10.3, length: 10.3, windows: 3, has a couch
width: 14.0, length: 6.7, windows: 2

Also make Office objects comparable to each other using the Comparable interface. Offices that have that have a greater area (width * length) should be considered "less" than other Offices so that they appear at the beginning of a sorted list. Offices that have the same area should be ordered by the number of windows they have, with Offices that have a greater amount of windows considered "less" than Offices that have less. If Offices still appear equal they should be compared by whether or not they have a couch. Offices with couches should be considered "less".

Type your solution here:


This is a class problem. Submit a complete Java class as described.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.