CS 201 - Computer Science I - Fall 2002
Project 3


Loyola College > Department of Computer Science > CS 201 > Projects > Project 3

Due: Monday, October 28th at 11:59pm.

Late policy: You lose 20% of the grade for the project every day after the due date until you submit your project. Projects that are more than four days late will not be accepted.

Topics: variables, expressions, assignment statements, methods, conditional statements, using pre-defined classes, using objects.


Top | Introduction | Assignment | Files | Grading | Advice | Submissions | Test Input

Introduction

Appraising a house is a complex process that attempts to estimate the current value of a house. At the heart of the process is the selection of "comparable sales" ("comps" for short), which are recent sales of houses in the same neighborhood as the one for which an estimate is desired (the "subject").

The bases of the estimate are the sale prices of the comps. Those prices, however, must be adjusted for several factors. For this project, you will consider the following factors:

In more concrete terms, for each comp, your program should compute an estimated value using the following steps.

In even more concrete terms, consider a house in ZIP 18951 that was built in 1992 with 4 bedrooms, 2 full bathrooms, 0 half baths, and 2000 ft2. Suppose there is one comp -- a house that sold for 100000 in 2000, was built in 1997, and has 3 bedrooms, 2 full bathrooms, 1 half bathroom, and 1800 ft2 total.

We first adjust the price of the comp for how long ago it sold. Suppose that houses have gone up in value 10% since 2000. The adjusted price is then $110000. (This is the price the comp would fetch in 2002).

Next, adjust for the age of the comp. The comp is 5 years old, so has (50 - 5) / 50 = 90% of its life left. The new adjusted price is then $110000 / 90% = $122222. (This is the current value of a brand new 3 bedroom, 2-and-one-half bath, 1800 ft2 house.)

Next, adjust for the size difference. First, add $10000 since the subject has one more bedroom than the comp. Then subtract $1000 since the subject has one fewer half bath than the comp. There is no adjustment for full bathrooms since the comp and the subject have the same number of full bathrooms. Assuming that the replacement cost is $25 per ft2 in ZIP 18951 we add an addtional $25 * 200 = $5000 to account for the 200 ft2 size difference between the two houses. The estimated price is now $136222. (This is the current value of a brand new 4 bedroom, 2 bath, 2000 ft2 house.)

The final adjustment is for the age of the subject. It is 10 years old, so has (50 - 10) / 50 = 80% of its useful life left. 80% of $136222, or $108977, is our final estimate for the value of the subject.

For this project, you will examine one comp (extra credit: two comps) from the same ZIP code as the subject. Your final estimate will be the average of the estimates obtained from each comp.

You should also provide an estimate based solely on the cost of construction per ft2, the age of the subject, and the value of a lot. (For example, we would estimate a 10 year old, 2000 ft2 house in an area where construction costs $60 per ft2 and lots cost $50000 to be $60 * 2000 * (50 - 10) / 50 + $50000 = $146000.)

Assignment

Add two methods to the given House class. The two methods must be called getValueByComps and getValueByCost.

getValueByComps takes a HomeSaleDatabase as its parameter. It should ask that database to give it the most recent comparable sale in the same ZIP code as the subject. That comp is returned as a HomeSale object. Once it has the HomeSale object, it can ask that object about its attributes (size, age, etc.) and use those values to compute the value of the subject house according to the process described above. The attributes of the subject house will be available in the instance varaibles zip, numBedrooms, numFullBaths, numHalfBaths, size, and constructionYear.

getValueByCost should determine the size of the subject house (by accessing the appropriate instance variable) and the construction cost per square foot and lot value in the subject's ZIP code and should then use those three values to determine the replacement cost.

Both methods should return estimates that are rounded to the nearest $100.

Predefined Classes

You will be given the code for three classes: AppraiserApplet, HomeSaleDatabase and HomeSale. Your code will not interact with the AppraiserApplet class A HomeSaleDatabase object will be used to hold the list of home sales from which to draw your comps. HomeSale objects hold the same information as House objects as well as information about the sale of a house. The public methods for those classes are described below.

HomeSaleDatabase

HomeSale HomeSale is essentially the same as House; the difference is that HomeSale can handle the two pieces of data (price and year of sale) that House does not.

Files

  • Make a directory called proj3 on your diskette.
  • Copy the files House.java, AppraiserApplet.java, HomeSaleDatabase.class, HomeSale.class, and houses.dat into your proj3 directory.

    The .class files contain compiled code, not source code, for the HomeSaleDatabase and HomeSale classes. You should not open these files. You should not need to see the source code for those classes.

    AppraiserApplet.java contains the code that manages the user interface. It creates the components and responds to button clicks. When the user clicks the button, the code reads the information from the TextFields and Choices and creates a House object to store that information. It then invokes the methods you're writing to obtain estimated values for that House. The values output by your methods (as return values) are read by the code in the applet and displayed in the appropriate locations.

    To run the applet, you should open the AppraiserApplet.java file and choose Run > Run as Applet from the window containing that file. Choosing Run > Run as Applet from the House.java window will not work.

    Grading:

    Advice

    Do not try to write the entire project at once! You will be bogged down with so many syntax and logic errors that fixing them all will be nearly impossible. Instead, write a small piece of the program, test it, and move on to the next piece. You can break the program into the following pieces.
    1. Use the HomeSaleDatabase object passed into getValueByComps to get a HomeSale object. Display the contents of the HomeSale using System.out.println to make sure this code works.
    2. Write code to compute an estimated value based on one comp. Output the value you compute after each step so you can see if those values are correct.
    3. (Extra credit) Add the code to handle a second comp if there is one. Think carefully about how to avoid writing the same code you did for the first comp all over again. (Hint: this might be a good place for a method).
    4. Add the code to compute the final estimate. Clean up the rest of your code.

    You can check your code against the applet below.

    Submissions

    Once you have written and debugged your code, submit your modified House.java file by e-mailing it to jglenn@cs.loyola.edu. Please include your file as an attachment if possible. Otherwise, cut and paste your code into the body of the message.

    Test Input (read after you have made substantial progress towards correct execution)

    The data for the sales is stored in the file houses.dat. The given data file contains
    
    18036
    4
    2
    1
    2700
    1996
    268500
    2000
    
    18034
    5
    2
    2
    3400
    1992
    330000
    2000
    
    18036
    4
    2
    1
    3300
    1997
    312000
    1999
    
    which defines three home sales:
    ZIP code Bedrooms Full Baths 1/2 Baths ft2 Year of Construction Price Year of Sale
    18036 4 2 1 2700 1996 268500 2000
    18034 5 2 2 3400 1992 330000 2000
    18036 4 2 1 3300 1997 312000 1999
    Based on this data, your program should compute estimated values of $296000 using the comparable sale method ($300200 if using both comparable sales) and $289800 using the replacement cost method for a 2700 ft2 house in ZIP 18036 with 4 bedrooms and 2-and-one-half bathrooms that was built in 1996.

    Your programs will tested with other data files, too. It is a good idea to do some testing of your own on other data files. If you do edit the data file, be sure to keep it in the same format. The data for each sale consists of a ZIP code, number of bedrooms, full bathrooms, and half bathrooms, a square footage, the year the house was built, its price, and the year of sale. There is only one piece of data on each line. Note that there is a blank line before each ZIP code (including the first one) and that there are no other blank lines and no spaces in the data file. If you do not follow this format, your program will crash when it tries to read the data file. The sales should be listed from most recent to least recent.