Computer Science 212
Project 2 hintsCopyright © 2008 by Dorothy L. Nixon. All rights reserved.
Test programs (download as ZIP file here)As discussed in class, it is recommended that you write class House first. It can be tested using the test programs below.
- ConsoleInput.java (to be used with some of the test programs below.)
- HouseTest1.java (Test constructor, get methods, toString, without catching exceptions.)
- HouseTest1A.java (Test constructor, get methods, toString, catching exceptions.)
- HouseTest2.java (Tests constructor, toString, and static isValidHouse method.)
- HouseTest3.java (Tests setPrice method, assuming a valid constructor and toString method.)
- HouseTest4.java (Tests equals method, assuming a valid constructor and toString method. Data file must contain at least three lines.)
- HouseWithDifferentEquals.java (House subclass, for testing symmetry of equals method with HouseTest4.java.)
- HouseTest5.java (Tests compareTo method, assuming a valid constructor and toString method. Data file must contain at least two lines.)
- TextFileInput.java (to be used with all the above test programs.)
Below are data files to be used with the test programs:
- project2-data-bad.txt (Data file containing both good and bad house data.)
- project2-data-good.txt (Data file containing good house data only.)
- project2-data-prelim-1.txt (Three-line data file for use with HouseTest4.java.)
- project2-data-prelim-2.txt (Three-line data file for use with HouseTest4.java.)
- project2-data-prelim-3.txt (Three-line data file for use with HouseTest4.java.)
The test programs may be downloaded in a ZIP file here.
In addition to the test programs and data files, project-2-hints.zip also contains a correctly-working House.class file so that you can see what the test programs will do with a correct version of class House.
Program development suggestionsAs mentioned in the instructions, it is recommended that you write and test class House, to be defined in House.java, before you write any other part of your program.
It is further recommended that you write and test class House itself piecemeal, in the following order:
- Write the class heading and class curly braces. Then declare the instance variables, then write the get methods and a preliminary version of the constructor which just sets the values of the instance variables without bothering with the error checking (or exception-throwing) yet. (You can add the error-checking later.) Then write the toString method and any private methods you may need to write in order for the toString method to generate a string which always has the proper format. Then test what you've written so far using HouseTest1.java and HouseTest1A.java, with data files project2-data-good.txt and project2-data-bad.txt.
- Write the recommended private static methods and the public isValidHouse method, which will call the private methods. Test the public isValidHouse method (and the private methods that it calls, directly or indirectly) using HouseTest2.java with data files project2-data-good.txt and project2-data-bad.txt.
- Add error-checking (and exception-throwing) to the constructor, using calls to your private static methods. Test your constructor error-checking (and thereby also do some further testing of your private static methods) using HouseTest1.java, HouseTest1A.java, and HouseTest2.java.
- Write the equals method. Test it using HouseTest4.java. Test it with all five of the data files provided here.
- Write the compareTo method. Test it using HouseTest5.java. Test it with data files project2-data-good.txt and project2-data-bad.txt.
Then write your main class Project2 and GUI class (HouseGUI) without any calls to sorting methods. Make sure it displays unsorted lists of pets properly on the two text areas where, in your completed project, the two sorted lists will appear.
Then write class HouseSorting and call its public methods in HouseGUI.java, so that the two sorted lists are displayed.