Cs1110 - home database query system - develop a quick


Objectives - practice the following concepts:

  • ArrayList of objects as the "internal database" - referred to below as the DB [NOTE: This is NOT a true database in terms of what we usually means in computing, managed by a database management system like MySQL or Oracle]
  • "Rapid Prototyping" to develop a program which is easily expandable in the future
  • User options menu
  • Input data from both a file and interactive user
  • Reading/Editing of user input (done in setters)
  • "Automatic" loading/saving of backup file data from/to the internal DB at the start/end of the program
  • Using the same file name for input file and output file (so output over-writes input file - CAUTION !!!)
  • Searching the DB for a single matchand for multiple matches
  • Adding and removing data from the DB

PROJECT BACKGROUND   A family friend wants you to develop a quick prototype program to help her keep track of the houses/condos she's looking at in her search to buy a new home.  You'll likely expand the program in the future (not in CS1110) to add such things as:

  • other data fields for each house
  • capability to search on other fields
  • betterediting, repeatedly asking user for correct data, etc.
  • adding pictures as fields
  • changing the internal "database" to EXTERNAL storage structures like hash files and indexed files instead (in CS3310 - Data & File Structures)
  • changing the storage structure to use an ACTUAL DATABASE using actual database management system software instead (in CS4430 - Database Systems) like MySQL or Oracle to store/access the data

PROJECT OVERVIEW (for asgn 8)This OOP program keeps a DBof houses for searching/updating/printing by the interactive user.  The data is stored in a .csv file for permanent storage while the program is NOT running.  It is automatically loaded into internal storage, the DB, (the ArrayList of objects) when the program starts, so that it can be searched more quickly.  The user is repeatedly presented with a menu of search (and other) options, which the program handles for them.   When the user is finished, the DB is dumped back to the same .csv file, since there may now be additional houses in the DB, or houses which were removed from the DB. 

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

The DB MUST be implemented as an ArrayList of House objects.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

DATA FILEHouseDB.csvNo header record.  The data here needs no cleaning/editing (unlike the data from the user for option 5 which DOES need cleaning/editing).  Each record contains these fields in this order:

                stAdr                      -street address uniquely identifier a particular house or condo

                city                         

sqFt                         - a positive integer between 100-5000 inclusive

numBR                   - number of bedrooms - a positive number between 0-5 inclusive

price                       - selling price - a positive integer between 10000 and 300000 inclusive

 

CAUTION !!!This file is both the INPUT file and the OUTPUT file.  So while you're testing, you should write to a DIFFERENT OUTPUT FILE - otherwise you'll keep LOSING your INPUT FILE DATA.   Once your program works, change the output file name to be the same as the input file.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * * * * * * * * * *

THE MENU OF QUERY OPTIONS

The menu is repeatedly presented to the user.  Use JOptionPane windows for user interaction.  Menu includes:

1)       search by street address (which uniquely identifies a particular house/condo - so results in 0 or 1 hit)

2)       search by size (which results in 0/1/many hits)

3)       search by number of bedrooms (which results in 0/1/many hits)

4)       list all houses

5)       add a new house

6)       remove a house

7)       done querying DB

The program then provides the user with the appropriate response.

Other INPUT the user provides (when prompted):

                For option 1          - street address (like 123 Hardy)

For option 2          - number of square feet (the threshold like 1400)

                                                                AND whether they want larger (>=) or smaller (<=) than that threshold number

For option 3          - number of bedrooms (like 3, or 0 for a studio type condo)

For option 5          - the following fields (separately):    stAdr, city, sqFt, numBR,  price

For option 6          - street address

 

Output (prompts) to user - in JOptionPane windows:

                For option 1/2/3/4              - the prompts to get the user input (see above)

                For option 5                          - the 5 prompts for the 5 fields (individually)

                For option 6                          - the prompt for the street address

 

Output (responses) to user - to the Console Window:

[NOTE:  I'm showing specific addresses, etc. just to demo the format.  Use the address/sqFeet/etc. that the user specified for the query]

                For option 1                          - TARGET:  12 Miller Rd.

For option 2                          - TARGET:  >= 1,400 sq. feet

For option 3                          - TARGET:  3 bedrooms

For option 4                          - LIST OF ALL HOUSES                    

For option 1/2/3/4              - all 5 fields nicely formatted (some spacing between fields,

include , in sqFt, include $ and , in the price)

                For option 5                          - reassurance message:      OK, house at 15 Fulton St. added

                For option 6                          -reassurance message:       OK, house at 2 Main St.removed

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

EDITING INPUT DATA:

A.       The data in the FILEis already correct - so put this data in the DB by using the object constructor (5 parameters) for each object (house) you create.

B.       The data from the interactive USER needs editing before it's stored.  So use the 5 setters for this.  Each setter

1)       uses a DialogBoxwindow (with prompt) to get the data from the user

2)       For sqFt, numBR, price fields

a.        checks that the user data is numeric/positive/integer/withinRange:

That is:                   sqFt         - a positive integer between 100-5000 inclusive

numBR   - a positive number between 0-5 inclusive

price       - a positive integer between 10000 and 300000 inclusive

b.       If data is wrong, itdisplays a MessageBox window indicating there's an error and what DEFAULT VALUE the program will automatically use:

That is:                   sqFt         - 1500

                                numBR   - 2

                                price       - 150000

3)       Stores the data in the instance variable

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

PROGRAM STRUCTURE

4 .java files for these 4 classes (containing the methods specified - perhaps additional methods too)

1)       The main program containing the main method, showMenu method                                                           

2)       A Utility class with2 static methods:  loadFileToDB and dumpDBToFile                                              

3)       A QueryHandler class of 6 static methods, one for each of the first 6 options:                                                       doAddressSearch, doSizeSearch, doBRSearch,                           listHouses, addHouse, removeHouse

4)       The OOP House class contains:   instance variables,

setters (for user data editing/setting), a constructor (for file data "setting"),

toString method (prepares a .csv record for file),   prettyPrint method (for option 1/2/3/4 printing)

NOTE:  Any of these classes could contain additional methods to further modularize the program.

Attachment:- HouseDB.rar

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Cs1110 - home database query system - develop a quick
Reference No:- TGS02381715

Now Priced at $15 (50% Discount)

Recommended (93%)

Rated (4.5/5)