Question: JAVA PROGRAMMING language write an interactive program with the following specifications. Specification 1: You will be given a text file (called houses.txt) that contains all
JAVA PROGRAMMING language
write an interactive program with the following specifications. Specification 1: You will be given a text file (called houses.txt) that contains all the data about the houses for sale. Your program should read this text file and populate the ArrayList of House objects that are on sale. Specification 2: Your program needs to prompt the user to enter the criteria they want to use to search for houses that they are interested in. In particular, the program should prompt the user to enter the following data:
- minimum price
- maximum price
- minimum area (i.e., square footage)
- maximum area (i.e., square footage)
- minimum number of bedrooms
- maximum number of bedrooms
This data entered by the user should be held in a Criteria object. Specification 3: Your program then needs to work with the entered Criteria object and the ArrayList of House objects created (i.e., the list of houses on sale) and find a set of houses on sale that match the entered criteria. This list should then be printed out on the screen, with a separator between every house data printed out.
A Class-Responsibility-Collaboration (CRC) card that describes the House class you need to code is presented below. The important points you need to focus on to write your code (i.e., the attributes instance variables of the class and their types, and the methods the class must have) are highlighted in RED.
| Class Name: | House | |
| Description: | ||
| /* General Description of the class */ It represents the details of a house for sale. | ||
| Subclass: | ||
| /* List any subclasses here */ None | ||
| Superclass: | ||
| /* List any class that this is a subclass of */ None | ||
| Attribute: | Type: | |
| /* List attributes and their types */ String address; int price; int area; int numBedrooms;
| ||
| Method: | Collaborating Classes: | |
| /* List Methods */ Constructor get (accessor) methods for all the instance variables public boolean satisfies(Criteria c) does this house meet the criteria specified by c. public String toString() to create a nice printable string describing the House data | Criteria | |
| Class Name: | Criteria | |
| Description: | ||
| /* General Description of the class */ This contains the criteria specified by the user to select houses. | ||
| Subclass: | ||
| /* List any subclasses here */ None | ||
| Superclass: | ||
| /* List any class that this is a subclass of */ None | ||
| Attribute: | Type: | |
| /* List attributes and their types */ int minimumPrice; int maximumPrice; int minimumArea; int maximumArea; int minimumNumberOfBedrooms; int maximumNumberOfBedrooms; | ||
| Method: | Collaborating Classes: | |
| /* List Methods */ Constructor Get (accessor) methods for all instance variables | ||
In addition to the above classes, you should code a HouseList class that encapsulates an ArrayList of House objects
| Class Name: | HouseList | |
| Description: | ||
| /* General Description of the class */ Contains an ArrayList of House objects. Reads the data from a file called houses.txt and adds them to the array list. Allows for searching of houses that satisfy criteria. | ||
| Subclass: | ||
| /* List any subclasses here */ None | ||
| Superclass: | ||
| /* List any class that this is a subclass of */ None | ||
| Attribute: | Type: | |
| /* List attributes and their types */ ArrayList houseList; | ArrayList | |
| Method: | Collaborating Classes: | |
| /* List Methods */ public HouseList(String fileName): reads data from file called fileName, creates House objects and adds them to the instance variable houseList public void printHouses(Criteria c) print all the houses that satisfy the criterion c public String getHouses(Criteria c) returns concatenated string of the details of all houses that satisfy the criterion c | ||
Finally, you need to write the tester class with the main program, which is described below (note that it must have a (private) instance variable of type HouseList, which is the class you just coded using the above CRC card):
| Class Name: | HouseListTester | |
| Description: | ||
| /* General Description of the class */ Interacts with the user. Accepts user criteria and arranges for search | ||
| Subclass: | ||
| /* List any subclasses here */ None | ||
| Superclass: | ||
| /* List any class that this is a subclass of */ None | ||
| Attribute: | Type: | |
| /* List attributes and their types */ HouseList availableHouses; | HouseList | |
| Method: | Collaborating Classes: | |
| /* List Methods */ This class should just have the main method, which operates as follows:
| ||
Use the following data for your HouseListTester (i.e., these are the criteria to use in your testing the data the user enters):
minPrice maxPrice minArea maxArea minBed maxBed
1000 500000 100 5000 0 10
1000 100000 500 1200 0 3
100000 200000 1000 2000 2 3
200000 300000 1500 4000 3 6
100000 500000 2500 5000 3 6
150000 300000 1500 4000 3 6
100000 200000 2500 5000 4 6
Data for the houses.txt file (Create the file in Notepad and copy and paste the data). Use the Scanner class to read data from the file.
123-canal-street 129000 1800 3
124-main-street 89000 1600 3
125-college-street 199000 2000 4
126-lincoln-street 56000 1200 2
127-state-street 82000 1500 3
223-canal-street 385000 4500 5
224-main-street 40000 800 2
225-college-street 37999 800 2
226-lincoln-street 125000 1200 2
227-state-street 130000 1250 3
323-canal-street 60000 900 2
324-main-street 80000 1000 2
325-college-street 45000 800 1
326-lincoln-street 63000 900 1
327-state-street 145000 1400 3
423-canal-street 199999 2000 4
424-main-street 250000 3500 5
425-college-street 350000 4600 6
426-lincoln-street 133000 1300 2
427-state-street 68000 850 1
523-canal-street 299999 3000 4
524-main-street 260000 2500 6
525-college-street 359000 4900 4
526-lincoln-street 233000 1900 2
527-state-street 58000 750 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
