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:
- how long ago the comp sold, since home values generally increase over time;
- the age of the houses, since a newer house is generally worth more than an
older house; and
- the size of the comp relative to the size of the subject ("size" means
number of bedrooms, bathrooms, and square footage).
In more concrete terms, for each comp, your program should compute an
estimated value using the following steps.
- Adjust the price of the comp for the time since its sale. If values
have increased 5% since the sale of the house, you should add 5% to the
sale price of the comp.
- Adjust the price of the comp for its age to get its value if it were
brand new. To do this, we estimate that a house has a useful lifespan of
50 years. If a house is 10 years old, it has (50 - 10) / 50 = 80%
of its useful life left.
The estimate of its new price is then 125% of the value computed in the
previous step (the reciprocal of 0.8 is 1.25).
- Adjust the price of the comp for the difference in size between it
and the subject. Add (or subtract) $10000 for each extra bedroom
the subject has (or lacks) when compared to the comp. Add or subtract
$2500 for each full bathroom, and $1000 for each half bathroom.
Finally, add or subtract to account for the difference in square footage.
The amount to add or subtract for each square foot is how much it costs
to build a ft2 of living space from scratch and depends on
the local market.
- The final estimate must take into account the age of the subject.
If the subject is 25 years old, then the price should be halved (our
formula gives a rather extreme adjustment, but things still work fairly
well when comparing houses of similar age).
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
- HomeSaleDatabase(): a constructor used to initialize the database.
- int countComparableSales(int zip): given a ZIP code, this method
returns the number of home sales in that ZIP code that are in the database.
- HomeSale getComparableSale(int zip): gets the data
for the most recent home sale in the given ZIP code.
- HomeSale getComparableSale(int zip, int which): gets the data
for a home sale in the given ZIP code. The second parameter determines
which comp you get data for. Passing 1 gives you the most recent sale.
Passing 2 gives you the next most recent sale, and so on.
- static double getAppreciation(int year): this method returns
the percentage by which home values have risen since the given year
(for 5%, it would return 5.0.
- static double getReplacementCost(int zip): returns the
cost to build a new house per ft2 in the given location.
- static double getLotValue(int zip): returns the
cost of a lot in the given location.
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.
- HomeSale(int, int, int, int, int, int, int, int): a constructor
to initialize the object's data to the given values. In order, the eight
ints are the ZIP code, number of bedrooms,
full bathrooms, half bathrooms, square footage, year of construction,
price, and year of sale.
- int getZIP(), int getPrice(), int getYearOfSale(),
int getNumBedrooms(), int getNumFullBaths(),
int getNumHalfBaths(), int getSquareFootage(), and
int getYearBuilt(): getters for all of the data the HomeSale
object holds.
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:
- 60% Execution. Partial credit will be granted depending on how
many test inputs your program successfully processes.
- 30% Design. The design score is based on how easy it is to
follow the logic of your code, how well you avoided repetitive code,
and how easy it would be to change your code if certain parameters changed.
- 10% Style. Style includes comments, indentation, and choice of
variable and method names.
- Substantial progress must be made towards correct execution
to earn the points for design and style.
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.
- 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.
- 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.
- (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).
- 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.