Bargain Bob's Discount Autos

Bargain Bob's Discount Autos

Due by midnight on Monday February 3rd

Objectives

This assignment should let you try your hand at class creation and usage, as well as simple text input and output. You should also get some practice using Ruby's built-in classes and methods, which are often more than enough for small problems.

Description

Last year, Bargain Bob, owner of Bargain Bob's Discount Autos, purchased a computer program to help him monitor his inventory (that box of 3" × 5" index cards just wasn't doing the trick). Since that time, Bob has acquired a few more employees and opened two more locations with computers using several different operating systems, and now needs one inventory application to run in all locations. You decide to flex your Ruby skills, and tell Bob, “I'll have it for you in two days.” Bob, who has no idea that it will probably take you less than an hour, smiles with approval and does that annoying thing he does where he points his finger at you like it's a gun and makes shooting noises. That's Bargain Bob for you…


Here's an example trace of how the program should work:


$ ./cars.rb
========================================
Welcome to Bargain Bob's Discount Autos!
----------------------------------------
(a)dd a new car
(d)elete a car
(l)ist all cars
(q)uit
----------------------------------------
Enter your choice: foo

----------------------------------------
I'm sorry, Bob.  I can't do that.
----------------------------------------
(a)dd a new car
(d)elete a car
(l)ist all cars
(q)uit
----------------------------------------
Enter your choice: a
----------------------------------------
Year: 1998
Make: Ford
Model: Mustang
Color: Red
VIN: 123ABC

Price: 8990
----------------------------------------
(a)dd a new car
(d)elete a car
(l)ist all cars
(q)uit
----------------------------------------
Enter your choice: a
----------------------------------------
Year: 1978
Make: Plymouth
Model: Duster
Color: Taupe

VIN: 321CBA
Price: 800
----------------------------------------
(a)dd a new car
(d)elete a car
(l)ist all cars
(q)uit
----------------------------------------
Enter your choice: l
----------------------------------------
1978 Plymouth Duster, Taupe (321CBA): $800
1998 Ford Mustang, Red (123ABC): $8990
TOTAL VALUE: $9790
----------------------------------------
(a)dd a new car
(d)elete a car
(l)ist all cars
(q)uit
----------------------------------------
Enter your choice: d
----------------------------------------
(1) 1978 Plymouth Duster, Taupe (321CBA): $800
(2) 1998 Ford Mustang, Red (123ABC): $8990
Car to delete: 2
----------------------------------------
(a)dd a new car
(d)elete a car
(l)ist all cars
(q)uit
----------------------------------------
Enter your choice: l

----------------------------------------
1978 Plymouth Duster, Taupe (321CBA): $800
TOTAL VALUE: $800
----------------------------------------
(a)dd a new car
(d)elete a car
(l)ist all cars
(q)uit
----------------------------------------
Enter your choice: q

Put your program in a file called cars.rb. Your code should have a Car class, which should implement the to_s method for printing, and the <=> method so that cars can be sorted (by year, as in the example, although if you can do a sort by year, then make, then model, etc, that would be optimal). Your program should check for bad input and respond appropriately. Hint: use a method that takes a block to guarantee that your input is acceptable.

Extra Credit

Add a menu option (s)ave that saves your user's data to a file which automatically loads again (if it exists) when the program starts. You may hard-code the name of the file so that it always uses the same file. A human readable format in the file is preferable, and ideally it should be easily opened by other well known applications. You might also want to ask the user if they want to save any time the program exits.

Grading Criteria

Your program will be graded on correctness, robustness, style, and elegance. You should attempt to use some of the Ruby constructs discussed in class (such as blocks) to make your code easy to read and easy to write. Anything that is not immediately obvious should be thoroughly commented. Your program interface does not have to match the example above exactly, but should be similar in feel. Do not use numbers for your menus unless necessary (i.e. the delete car option).

Submission Checklist

  • cars.rb