1. Engineering
  2. Computer Science
  3. the house class sophie sally and jack have decided to...

Question: the house class sophie sally and jack have decided to...

Question details

The House Class

Sophie, Sally and Jack have decided to develop a housing subdivision. The first thing they'll need is a House class. The houses will be all be very similar: a living area for formal entertainment, a family area for everyday activities, and some number of bedrooms, each with a bath. The houses will also have various amounts of land surrounding them.

Write a class House. The purpose of a House object is to represent a single house with its plot of land in a subdivision. The House class has the following specification:

Instance Variables

  • instance variable of type int for the number of bedrooms.  
  • instance variable of type double for the size in square feet of the family room
  • instance variable of type double for the size in square feet of the living room
  • instance variable of type String that describes the style of the house ("Colonial," "Ranch," "motte-and-bailey," etc)
  • instance variable of type double for the size in acres of the plot that surrounds the house

Constructors

House has two constructors

  • a no-argument constructors

a constructor that takes five parameterS (in this order):

  1. the style of the house
  2. the area of the family room
  3. the area of the living room
  4. the number of bedrooms,
  5. the size of the plot the house sits on

Accessors

House has getters for all instance variables:

  • getBedrooms
  • getFamilyRoomArea
  • getLivingRoomArea
  • getPlot
  • getStyle

getTotalArea (This method take no parameters, and returns a double value representing the total square feet of the house. Each bedroom is 300 square feet.)

int compareArea(House otherHouse) returns

  • a negative value (the exact value doesn't matter--only that it be less than zero) if the current house's total area is smaller than the total area of otherHouse
  • a positive number (the exact value doesn't matter--only that it be greater than zero) if the current house's total area is larger than the total area of otherHouse
  • 0 if the two houses have exactly the same total area

toString that returns something similar to "House style = Colonial, bedrooms=3, family room area=700.0, living room area=500.0, plot=0.7, square feet=2100.0"

Mutators

House has setters for all instance variables

  • setBedrooms
  • setFamilRoomArea
  • setLivingRoomArea
  • setPlot
  • setStyle

Tester

Write a class with a main method to test House. Do not put your main method in the House class. Your tester should create at least two House objects, set different values for the Style, Bedrooms, plot, etc. The tester should especially test that compareArea works as expected.  

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution