Homework 7 – House Hunter

Objective

You will write a House class to encapsulate the information related to an individual house. You will write another HouseHunter class that uses this House class to search through the entered houses for different traits – number of bedrooms, cost, etc.. You must write the classes in standard OOP Object Oriented Programming form – using private member variables, using a constructor, accessors, etc. You will also check for valid input at all points. You do not have to check to see if they enter a number for text or vice versa but that numbers entered for numbers make sense.

The House Class

1.      The attributes of the house class are:

a.      Address

b.      Cost

c.      Number of Baths (note that houses have e.g. 2.5 baths)

d.      Number of Bedrooms

2.      Define a constructor to set all of these at once.

3.      Define any accessors you may need.

4.      Define any mutators you may need. (Which, if any?)

5.      Define a toString() method to print a house. It should print all the information in a pretty form. See the sample output if you need inspiration.

The HouseHunter Class

This is just a driver for our program. You can do everything in the main() method but some helper methods may help.  See the output. Also check the following basic algorithm sketch:

1.      Read in the number of houses. It must be more than 1.

2.      Read in the data for each house.

a.      You must check the input before instantiating the House class. (We will see how to do this better with exceptions soon). Loops make sense here.

b.      On invalid input, you should inform the user and take in a new value until it is valid.

c.      The conditions for the input are:

                                                    i.     The cost, number of bathrooms, and number of bedroom must all be positive.

                                                   ii.     The Address must have both a number and a letter.

1.      Character.isDigit(char c) to see if a c is a digit

2.      Character.isAlphabetic(char c) to see c is an alphabetic char

3.      Consider boolean variables here

3.      Instantiate and store the house

4.      House searching

a.      Prompt the user to select one of the following criteria

                                                    i.     Maximum Cost

                                                   ii.     Minimum number of bedrooms

                                                  iii.     Minimum number of bathrooms

b.      Display all houses satisfying the criteria

c.      Ask users if they want to search again

 

Sample Output

Reading Data In:

Searching