Real Estate Listings Using Java



Problem Statement: Suppose you are looking to buy a house. You have certain criteria in mind such as: price range, square-footage, number of bedrooms, etc. You would like to enter your criteria and expect that the real estate program to come up with a house, or possibly, a list of houses, that satisfy those criteria. You are asked to write a program that works on those lines.

A “House” (i.e. a house that is for sale) for us is defined by the following data:

  • address – This is the street address such as 23-Linden-Avenue. Even though there can be many words, we make it one word by introducing hyphens.

  • price – This is a number like 149999

  • area – the square-footage of the house, again a number, such as 1800

  • numberOfBedrooms – again, a small number, like 3

A “HouseList” consists of an ArrayList of ‘House’s that are for sale.

A “Critreia” represents a buyer’s criteria. A ‘criteria’ consists of the following data:

  • minimumPrice

  • maximumPrice

  • minimumArea

  • maximumArea

  • minimumNumberOfBedrooms

  • maximumNumberOfBedrooms

You are asked to 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:

  1. minimum price

  2. maximum price

  3. minimum area (i.e., square footage)

  4. maximum area (i.e., square footage)

  5. minimum number of bedrooms

  6. 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:

/* 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

Collaborating Classes:

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:

/* List attributes and their types */

int minimumPrice;

int maximumPrice;

int minimumArea;

int maximumArea;

int minimumNumberOfBedrooms;

int maximumNumberOfBedrooms;

Method:

/* 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<House> houseList;

ArrayList<House>

Method:

/* 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) – returnsconcatenated 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:

/* List attributes and their types */

HouseList availableHouses;

Type:

HouseList

Method:

/* List Methods */

This class should just have the main method, which operates as follows:

  1. Create the HouseList object names availableHouses using “houses.txt”

  2. Read in seven different Criteria objects with varying upper and lower limits for price, area and number of bedrooms.

  3. For each criteria, use printHouses to print a list of houses that satisfy the criterion.

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



We are providing online JavaFx project help at an affordable prices, if you need any help related to java or need solution of above task then you can contact us at contact@codersarts.com

65 views0 comments