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.

Apartment class

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:

  • The base cost for 1,500 square feet is $400. For each additional 100 square feet or portion of 100 square feet, add an additional $50. There is no cost reduction for any size less than 1,500 square feet.
  • Add $300 for each bedroom.
  • Add $200 for each bathroom.
  • Add $100 for each garage.
  • To the total of the above items, add an additional 55% for a downtown location and subtract 25% for a far suburbs location. F. If furnished, increase the total by 10%.

Override the inherited calculateCost method to return the string:

"The cost on an apartment with" + (add feature list here) + "is "+ cost + "per month."

Condo Class

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:

  • The base cost for 3,000 square feet is $280,000. Add $3,800 for each additional 100 square feet or portion of 100 square feet. Subtract $1,500 for each 100 square feet or portion of 100 square feet the square footage is reduced down to the minimum
  • Add $3,400 for each bedroom.
  • Add $1,800 for each bathroom.
  • Add 40% of the total of A, B, and C above for a condominium with two floors
  • Add $1,500 for each garage
  • To the total of the above items, add an additional 60% for a downtown location, subtract 10% for a suburbs location, and 25% for a far suburbs location

Override the inherited calculateCost method to return the string:

"The cost of a condominium with" + (add feature list here) +" is" + cost + "."

House class

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:

  • The base cost for 3,200 square feet is $165,000. Add $3,800 for each additional 100 square feet or portion of 100 square feet. Subtract $1,200 for each 100 square feet or portion of 100 square feet square footage is reduced down to the minimum
  • Add $6,200 for each bedroom.
  • Add $3,600 for each bathroom.
  • Add 13.6% of A for a basement.
  • Add $1,750 for each garage.
  • Add $20,000 for a two story and $12,500 for a tri-level.
  • Add $40,000 per acre for anything above 0.20 acres. ((acres - .20) * 40000)
  • To the total of the above items, add 35% for a city location and subtract 12.5% for a far suburbs location.

Override the inherited calculateCost method to return the string:

“ The cost of a house with “+ (add feature here) + “ is “ + cost”.”

Office Class

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:

  • The base cost of 120,000 square feet is $1,350,000. Add $4,500 for each additional 100 square feet or portion of 100 square feet. Subtract $3,000 for each 100 square feet or portion of 100 square feet square footage is reduced down to the minimum
  • Add $18,900 for each pair of restrooms
  • Add $3,000 for each 100 parking spaces (or portion of 100)
  • Add $85,000 for each elevator
  • To the total of the above items, subtract 16.5% for a far suburbs location and add 70% for a downtown location
  • Add $50,000 per acre for anything above 0.50 acres. ((acres - .50) * 50000) .

Override the inherited calculateCost method to return the string:

"The cost of an office building with" + (add feature list here) + " is" + cost + "."

Warehouse Class

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:

  • The base cost of 200,000 square feet is $875,000. Add $1,250 for each additional 100 square feet or portion of 100 square feet.
  • Add $12,000 for each office.
  • Add $18,200 for each pair of restrooms.
  • Add $3,000 for each 50 parking spaces (or part of 50).
  • Add $11,125 for each truck bay.
  • To the total of the above items, add 30% for a city location and subtract 10% for a far suburbs location.
  • Add $30,000 per acre for anything above 2.0 acres. ((acres - 2.0) * 30000) .

Override the inherited calculateCost method to return the string:

"The cost of a warehouse with" + (add feature list here) +" is" + cost + "."
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.