CS541: Project #1


Overview

In this project, you'll create a simple information system to store data about cars using Java.

Due date: Sept 22 @ 11:59pm



Updates


Getting Started

Environment Setup

You will need to add the following directory to your PATH environment variable: /opt/csw/bin

Here's some code to get you started:

Note, in previous classes, you've probably used the venerable UNIX utility make to build your projects. In the Java world, nobody uses that anymore. So enjoy a helpful dose of the real-world and behold the beauty of Apache ant. The configuration for ant is build.xml, which is, as the file extension would seem to imply, written in XML, which we'll talk about later in the semester.

It's already been written for you, so you shouldn't need to do much. To build, just type the following command. The resulting .class files will be placed in bin/.

$ ant

To clean out old .class files, type the command:

$ ant clean

Also included is a script run.sh Feel free to modify this to run your application with any additional parameters.

$ ./run.sh

Top


Requirements

You will write a console-based Java application to serve as a database for car information. The application will sport three primary features: adding cars, saving (and loading) information about cars from disk, and querying that data. Your database will store the makes of cars, as well as models. A make is composed of a name and a country of origin, whereas a model is composed of a name, a make, a year, and a price.

When you start your application, you should present the user with the following prompt:

 
CS541 Project 1
Please enter a command.  Enter 'help' for a list of commands.
 
> 

If you enter help, you will print the following:

 
add_make MAKE COUNTRY - add a car of MAKE made in COUNTRY
add_model NAME MAKE YEAR PRICE - add a model of a car named NAME by MAKE in YEAR valued at PRICE
makes - print a listing of all makes in the DB
models - print a listing of all models in the DB
models_by_price OP PRICE - print a listing of models in the DB, filtered by price
makes_by_origin COUNTRY - print a listing of makes in the DB, filtered by country
 
ordered_models_per_make MAKE - print a listing of models made by MAKE ordered (in descending way) by price
 
save FILENAME - save the contents of the DB to FILENAME
load FILENAME - load the contents of the DB from FILENAME
exit - goodbye!

Implement each of these commands. A detailed description and example of each command is as follows. For any command, if the input it not properly formed or something "bad" happens, simply output the message:

 
Error.

Otherwise, if the command executes successfully, output the message:

 
Command executed successfully.

Top


Commands

add_make

MAKE - a name for the make
COUNTRY - a name for the country

Add a make named MAKE made in COUNTRY to the database. Both parameters are mandatory and must be alphanumeric. Adding duplicate MAKE names is not allowed.

Example:

 
> add_make Honda Japan
 
Command executed successfully.
 
> add_make Ford USA
 
Command executed successfully.
 
> add_make Honda Random
 
Error.
 
> add_make foo bar baz
 
Error.

Top

add_model

Parameters:

NAME - name of the model
MAKE - name of the make of the car
YEAR - (integer) year of the vehicle
PRICE - (integer) MSRP in dollars

Add a model named NAME, made by MAKE in YEAR, valued at PRICE. All parameters are mandatory. The MAKE must already exist in the database. Names must be alphanumeric; both the year and the price must be integers. Adding duplicate model names (with respect to an individual make) is not allowed.

Example:

 
> add_model Civic Honda 2006 15000
 
Command executed successfully.
 
> add_model Element Honda 2006 25000
 
Command executed successfully.
 
> add_model 4Runner Toyota 2005
 
Error.
 
> add_model Accord Honda lkajsdfkj
 
Error.

Top

makes

Print out all makes in the database.

Example:

 
> makes
 
Honda Japan
Ford USA
 
Command executed successfully.
 

Top

models

Print out all models in the database, together with the associated makes.

Example:

 
> makes
 
Civic 2006 @ 15000, Honda in Japan
Element 2006 @ 25000, Honda in Japan
 
Command executed successfully.

Top

models_by_price

Parameters:

OP - one of <, > or =
PRICE - (integer) price to filter by

Print out all the models, filtered by price. For this command, all you need to print out is the name of the model. For each of the models, test it against the following condition: OP PRICE. Print out all models that satisfy said condition.

Example:

 
> models_by_price < 20000
 
Civic
 
Command executed successfully.
 
> models_by_price > 30000
 
Command executed successfully.
 
> models_by_price ^ 20
 
Error.
 

Top

makes_by_origin

Parameters:

ORIGIN - the country of origin to filter by

Print out all makes in the database, filtered by country of origin.

Example:

 
> makes_by_origin USA
 
Ford
 
Command executed successfully.
 
> makes_by_origin Brazil
 
Command executed successfully.
 
> makes_by_origin
 
Error.

Top

ordered_models_per_make

Parameters:

MAKE - the make whose models will be listed

Print out a listing of all models (name and price) made by MAKE ordered (in descending way) by price

Example:

> ordered_models_per_make Honda
 
Element 25000
Civic   15000
 
Command executed successfully.
 
> ordered_models_per_make
 
Error.
 

Top

save

Parameters:

FILENAME - the filename to save to database to

Save the contents of the database to a file. You may choose the file format as you see fit.

Example omitted.

Top

load

Parameters:

FILENAME - the filename to load the database from

Load the contents of the database from a file. You are only required to support the file format written out by your implementation of the save command. This command will implicitly clear out existing data before loading the contents of FILENAME.

Example omitted.

Top

exit

Exit the application. Unsaved data will be lost.

Top


Evaluation

Primarily, your work will be evaluated based on how well your project meets the spec. We will use automated grading utilizing diff (with the -bwi flags). So it's important that your program not crash; catch errors and continue operation. Good programming practices and thorough testing will be rewarded.

We might do some benchmarks to see who has the fastest project-- or who stores the data on disk most efficiently.

To build your project, we will execute the following:

 
$ ant compile

To run your project, we will execute the following:

 
./run.sh

Top


Submitting your work

Please create a README file that contains identifying information. For example:

 
CS541 - Project 1
 
Author:     John Doe
Login:      jdoe
Email:      jdoe@cs.purdue.edu
 
Include here anything you might want us to know when grading your project.

To turn in your project, execute the following command in your top-level directory.

 
    $ turnin -c cs541 -p proj1 .

Top


Some final notes:

Top


Back