Due date: see Oncourse Modules or Assignments
50 points
Learning Objectives
- Develop proficiency in arrays.
- Reinforce skills of writing classes, loops, and conditionals.
Instructions
Summary
Write a Floor class, representing a floor or storey in a building. A Floor is characterized by its two horizontal dimensions (width and depth—we assume it is a rectangle) and number of rooms. Your class should include a constructor and methods to retrieve the width, depth, number of rooms, and area of the floor.
Write a Building class, representing a multi-storey building. The building must have a field which is an array of Floors. Your class should include a constructor, and methods to compute the total number of rooms, the total area, and the minimum and maximum number of rooms on a floor.
Follow the Coding Standards through Chapter 8, Arrays.
Specifications
Floor Class
- Constructor
- Parameters: width, breadth, and number of rooms
- Action: initializes any fields needed so that the methods specified below can work.
- Methods
- A method to retrieve the number of rooms on the floor
- Parameters: none
- Returns: int
- A method to retrieve the floor’s width
- Parameters: none
- Returns: double
- A method to retrieve the floor’s breadth
- Parameters: none
- Returns: double
- A method to retrieve the area of the floor
- Parameters: none
- Returns: double
These are the required methods. I am leaving the method names up to your choice, so remember to follow the guidelines for good style in naming. There is no need to define setters for the fields, since these characteristics rarely change, once a floor is built. You may, however, define additional methods if you wish.
Building Class
- Constructor
- Parameter: an array of Floor objects
- Action: initializes a field which is an array of Floor objects, equal to the parameter.
- Note: both the parameter and the field must be an array of Floor objects—not an ArrayList, not any other type of collection, and not an array or arrays of some other type of elements.
- Methods
- A method to return the total number of rooms, that is, the sum of the number of rooms on all floors. For example, if there are three floors with 10, 12, and 15 rooms, this method returns 37.
- Parameters: none
- Returns: int
- A method to return the minimum number of rooms on a floor. For example, if there are four floors with 10, 12, 8, and 15 rooms, this method returns 8.
- Parameters: none
- Returns: int
- A method to return the maximum number of rooms on a floor. For example, if there are four floors with 10, 12, 8, and 15 rooms, this method returns 15.
- Parameters: none
- Returns: int
- A method to return the total floor area of all the floors in the building. For example, if there are two floors with dimensions 200 x 200, and one floor with dimensions 180 x 180, this method returns 200 * 200 + 200 * 200 + 180 * 180, which is 112,400.
- Parameters: none
- Returns: double
- A main method to test the class.
- The main method should create an instance of Building with the floors described in Table 1.
- It should print the building’s total number of rooms, the minimum and maximum number of rooms on a floor, and total floor area, using the methods specified above.
These are the required methods. I am leaving most of the method names up to your choice, so remember to follow the guidelines for good style in naming. There is no need to define a setter or getter for the field. You may, however, define additional methods if you wish.
Table 1: Floors for Testing
| 100 |
200 |
16 |
Ground floor |
| 100 |
200 |
12 |
1st floor |
| 100 |
200 |
10 |
2nd floor |
| 80 |
160 |
12 |
3rd floor |
| 60 |
140 |
10 |
Top floor |
What to Turn in
Through Oncourse Assignments, turn in the Java source file(s) and captured output of running the test (i.e., main method of the Building class), either as a screenshot, or a text file with extension .txt.
Grading Criteria
__ of 10 points. Correctness of Floor class
- Constructor, 3 points
- Four required methods, 1 point each = 4 points
- Other, 3 points
__ of 40 points. Correctness of Building class
- Constructor, 3 points
- Two required “total” methods (number of rooms, area), 5 points each = 10 points
- Two required “min” and “max” methods, 7 points each = 14 points
- main method, 10 points
- other, 3 points
__ of 5 points. Program style, Coding Standards through Ch. 8
__ of 5 points. Program testing, as instructed
__ of 50 points total