Question
Specification for Java classes are as follows : A building has a number of floors, and a number of windows. A house is a building.
Specification for Java classes are as follows:
A building has a number of floors, and a number of windows.
A house is a building.
A garage is a building. (This isnt Florida-like its a detached garage.)
A room has a length, width, a floor covering, and a number of closets.
You can never create an instance of a building, but every object that is a building must have a method that calculates the floor space, i.e., the Building class is abstract, and has an abstract method.
A house has a number of bathrooms, and an array of Rooms.
A house has a method that returns the average size of the Rooms.
A Garage can hold some number of cars, and it may have a cement floor or a gravel floor. A garage has a length and a width.
1. Describe the inheritance hierarchy. What inherits from what. (just class names it's small. Include the Object class in your hierarchy).
2. Implement the specification in Java classes.
You must use the following mechanisms correctly:
Inheritance is a
Composition has a
Constructor methods
Accessor / mutator methods = getters, setters
Arrays of objects you can use ArrayList if you know how
Passing arrays of objects to methods or an ArrayList
Abstract classes and methods
Access modifiers public, private (you might find a reason to use protected, its not all that common)
toString() methods in each class
the super keyword
method overriding
method overloading
This program also requires you to demonstrate the OO concepts of: encapsulation
polymorphism
Include a test class that has a main method. This test program will make instances of your classes and output the text representation of the objects using the toString() methods. There should be enough comments in the output so that it is easy to see which classes are being tested.
Additional specs:
Your product for the assignment is the House, Building, Room, Garage classes. The class with the main is used to test these classes. Consider that there might be a large project in the future for a real-estate company, and the classes will be put into use in that project. (There wont be but imagining the use of the classes will help you to make them more convenient for the user.)
No user input is required you can hard-code some data in the main method.
Only test methods (main in this case) use the System.out.println() method. The purpose of the classes is to store and manipulate data. Input and output is not included in the data storage and manipulation classes.
A house will calculate its floor space by looping through the array (ArrayList) of rooms, and accumulating the floor space. Don't worry about the space used by a closet, you can assume that it is included in the size of the room. OK bigger hint here. The Building class must have an abstract method signature that imposes on all of its subclasses that they override this method to calculate the floor space.
Work incrementally. Start by making a Room class, and testing it. Then make the Building and Garage classes, test them. Then make the House class, and test it.
The constructor for the house class has an array of rooms as a parameter, i.e. you must have an array of Room[] (or an ArrayList of room objects) to call the constructor for the House
The building class is the only class that stores and manipulates the number of windows, and floors. An abstract class usually has some concrete (non-abstract) methods.
All garage objects have exactly one floor. Garages are not part of a House. Garages do NOT have a room in them. Even though the description of the Room sounds like you might be able to re-use that code in the Garage class, dont do it, you would have to deal with closets in the Garage, and there arent any.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started