This project will require the creation of a class hierarchy as follows: See image.
A critical part of working on a project, in additional to the programming, is design. As such, most of the design of this project will be up to you. But in so doing (and to get a better project grade), you need to pay attention to certain design guidelines. All of these classes should be placed in the package named myprojectclasses.
First, all instance variables and their associated methods should be placed in the highest class needed for inheritance to occur. For example, since all of the lowest level classes need squareFootage, it's placed in Building so each hierarchical path has access to it. Likewise, since bedrooms is needed by the three subclasses of Home but not the two subclasses of Business, it should be placed in Home. And since elevators is only needed in Office, it should be placed there.
Second, make sure that methods that will need to be overridden because each subclass will need to use it differently (like calculateCost) are labeled as abstract at the appropriate level.
Third, make sure that the instance variables , are private and that public get and set methods are provided at the appropriate level. The methods should be named getFieldName and setFieldName for the respective fields. All concrete ,classes should use calculateCost to return the results.
Fourth, make sure you incorporate two constructors for all concrete classes. The first should be a s no-argument (default) constructor that sets all instance variables to their respective default values.The second constructor should require values be submitted for all appropriate instance variables. The order of these variables should be the same as they are listed on the appropriate sheet.
Fifth, make sure your set methods also validate the data to keep all instance variables in a consistent state.
Sixth, make good use of your own methods. This is especially true when you are setting up your constructors. Keep redundant code to a minimum.
Seventh, your output should include a listing of the options selected to determine the final cost along with the final cost. For example, your output for an apartment might look like:
The cost of the apartment with 1,834 square feet of living space, 2 bedrooms, 1 bathroom, on 1 floor, located in the suburbs, and with 1 garage, would be $984 per month.
Make sure your output is grammatically correct. For example, your output should say 2 bedrooms, plural, and not bedroom, singular. Likewise, it should say 1 bathroom, singular, not bathrooms, plural. (Hint: The conditional statement could be used here!)
Eighth, the concatenated result for each concrete class should be the string returned by the calculateCost method.
And finally, you will need to develop test programs to insure that your classes work according to the specifications. Your test programs should include specific data for each type of building and receive the total cost for that building as well as use the default parameters to determine the cost. Along with your test programs and project, submit the test plan you used to test your project code. Call your test programs TestCondo, TestApartment, TestHouse, TestOffice, and TestWarehouse. These should be placed in a package named testmyprojectclasses. You test data should match your test plan. (Hint: Spreadsheets are a good tool to use here.) Submit your test plans in files named CondoData,ApartmentData, HouseData, OfficeData, and WarehouseData.
Use the class information on the following pages to create your project. When deciding where to place various instance variables and methods, look for commonalities. Part of your grade depends on the use of inheritance and polymorphism and encapsulation.
There may be times that the creation and implementation of an interface might be a better design implementation. You are free to alter the hierarchical structure on the previous page to include interfaces as you choose. This is strictly optional, but may improve design. Under no circumstances, however, are you allowed to alter the original class hierarchy.
The Apartment class should use the following defaults: squareFootage - 1,500 (Valid range is 1,000 to 3,600 square feet) . If value is not in the range set it to 1500 by default( Use no argument constructor for that)
bedrooms - 2. (Valid values are 1, 2, and 3)
bathrooms - 1 (Valid values are 1, 2, and 3)
location - 20.0 (suburbs) ( valid values are downtown(0.00-2.0), city (> 2.00-12.00), suburbs (>12.00-30.00) and far suburbs(>30.00)
garage - 0 (Valid values are 0, 1, and 2)
furnished - false (Valid values are true and false)
The cost of the apartment should be calculated:
Override the inherited calculateCost method to return the string:
"The cost on an apartment with" + (add feature list here) + "is "+ cost + "per month."
squareFootage - 3,000 (Valid range is 2,500 to 5,500 square feet)
bedrooms - 2 (Valid values are 1, 2, 3, and 4)
bathrooms - 2 (Valid values are 1, 2, and 3)
floors - 1 (Valid values are 1 and 2)
location - 8.0 (city) (Valid values are downtown (0.0 - 2.0), city (> 2.0 - 12.0), suburbs (> 12.0 - 30.0), and far suburbs (> 30.0))
garage - 0 (Valid values are 0, 1, and 2)
The cost of the condominium should be calculated:
Override the inherited calculateCost method to return the string:
"The cost of a condominium with" + (add feature list here) +" is" + cost + "."
The House class should use the following defaults:
squareFootage - 3,200 (Valid range is 2,800 to 6,400 square feet)
bedrooms – 3 (Valid values are 1, 2, 3, 4, and 5)
bathrooms - 2 (Valid values are 1, 2, 3, and 4)
floors - 1 (Valid values are 1, 2, and 3 with 1 being a ranch style (1 floor), 2 being a two story style (2 floors), and 3 being a tri-level style (3 floors).
basement - false (none) (Valid values are true for a basement and false for no basement.
location - 24.0 (suburbs) (Valid values are city (> 2.0 - 12.0), suburbs (> 12.0 - 30.0), and far suburbs (> 30.0))
garage - 2 (Valid values are 1, 2, and 3)
lotSize - 0.20 (Valid range is 0.20 to 5.00 acres)
The cost of the house should be calculated:
Override the inherited calculateCost method to return the string:
“ The cost of a house with “+ (add feature here) + “ is “ + cost”.”
The Office class should use the following defaults:
squareFootage - 120,000 (Valid range is 100,000 to 1,200,000 square feet)
restrooms - 6 (Valid values are 2 through 40, minimum 2 per floor, must be in pairs, floors determine default value)
floors - 3 (Valid values are 1 through 20)
location - 18.0 (suburbs) (Valid values are downtown (0.0 - 2.0), city (> 2.0 - 12.0), suburbs (> 12.0 - 30.0), and far suburbs (> 30.0))
parkingSpaces - 100 (Valid values are 100 through 400)
elevators - 1 (Valid values are 0 for 1 floor, minimum 1 for 2 or 3 floors, 2 for 4 through 7 floors, 3 for 8 through 12 floors, and 4 for more than 12 floors - default determined by floors)
lotSize - 1.0 (Valid range is 0.5 to 10.0 acres.)
The cost of the office should be calculated:
Override the inherited calculateCost method to return the string:
"The cost of an office building with" + (add feature list here) + " is" + cost + "."
The Warehouse class should use the following defaults:
squareFootage - 200,000 (Valid range is 200,000 to 1,000,000 square feet)
offices - 5 (Valid values are 1 through 20)
restrooms - 2 (Valid values are 2, 4, 6, 8, or 10)
location - 18.0 (suburbs) (Valid values are city (> 2.0 - 12.0), suburbs (> 12.0 - 30.0), and far suburbs (> 30.0))
parkingSpaces - 50 (Valid values are 50 through 300)
truckBays - 2 (Valid values are 2 through 15)
lotSize - 5.0 (Valid range is 2.0 to 20.0 acres.)
The cost of the warehouse should be calculated:
Override the inherited calculateCost method to return the string:
"The cost of a warehouse with" + (add feature list here) +" is" + cost + "."