| Project #6 |
CMSC 131 |
| Due: Friday,
November 30th before 11pm |
Object-Oriented Programming
I |
| Type of Project:
CLOSED
|
Fall 2012 |
Objective
This project will give you practice with interfaces, arrays, working in a
complex environment where several classes depend on one another, dealing with
mutable vs. immutable and careful array copying.
Overview
This project will simulate an operational exotic pet store.
It isn't very realistic, but it may amuse you.
The image below represents the GUI
(Graphical User Interface) that is provided.

The entire project can be completed without ever running the
GUI, the GUI is just for fun.
I would encourage you to implement your classes according to the
JavaDoc, and test them using your
own JUnit tests.
Although we are not grading your tests this time it really is the
best way to test this project as you build it, and you are always
expected to write them as any good Java programmer would.
Once you believe that your classes are working properly, you can
have some fun playing around with the GUI.
Notes on the GUI:
- At the top you see the amount of cash that the pet store currently has
available.
- The left side of the screen represents the ordering options for the
pet store (you can easily add menageries to the menu by clicking the buttons
at the top of the Menu.)
- The right side represents your inventory (you can easily add items to
the inventory by clicking the delivery buttons -- but your available cash
will decrease by the wholesale cost of the items that are delivered.)
- Beside each menagerie on the options list there is an "order"
button.
Clicking one of these buttons is supposed to simulate a customer ordering
one of the menageries from your options list:
the appropriate items will be removed from your inventory,
and your "available cash" will be increased
by the retail value of the menagerie.
Things that are Provided for You
As usual, we are supplying JavaDoc to provide
most of the project specification.
- First, read the documentation for the Listable interface,
which has been written for you.
In this project there will be two classes that implement this interface.
They are: Animal and Menagerie.
- Next, read the documentation for the Animal class,
which has been written for you.
Note that the Animal class is
immutable and implements the Listable interface.
You will need to use this class while implementing your
classes, so read it and make sure you understand how it works.
- We have also written a class called GUIDriver, which
contains the main method that you can run to invoke the GUI.
What You Must Implement
You will be implementing the following classes. It is strongly
recommended that you implement them in the order below:
- SortedListOfImmutables -- This is a list that can be used
to store many different kinds of objects. The list always starts off
empty, and as objects are added to the list, they are inserted in such a way
that the list is always in alphabetical order. The list can hold any
types of objects that satisfy two requirements:
- The objects must be immutable.
- The objects must be instances of a class that implements the
Listable interface.
This project will use this class to store lists of Animal objects,
and lists of Menagerie objects.
- Menagerie -- an entry on the options list.
The Menagerie
class implements the Listable interface. Each Menagerie
consists of a name (which is a String) and a list of animals (which is a
SortedListOfImmutables containing Animal objects).
Once a menagerie is created, it
will never change. (It is an immutable class.)
- PetStore -- the top-level class representing the
pet store. A PetStore consists of a name (which is a String), a
options list (which is a SortedListOfImmutables containing Menagerie objects),
an inventory (which is a SortedListOfImmutables containing Animal objects),
and a certain amount of available cash (an int, representing the amount in
pennies). If you think about it, the options list is very interesting:
It is essentially a list of lists. (The options list is a list of
menageries; menageries are basically lists of animal objects.)
Hints:
- The methods of the Menagerie class should be very short.
The menagerie
class has an internal variable called animalList, and some of the methods of
the menagerie class should just be calling instance methods on this variable
instead of re-writing essentially the same code!
- The PetStore class has instance variables called options and inventory.
The methods of the PetStore class should rely heavily on making calls to
instance methods of these two variables instead of re-writing essentially
the same code!
- When writing the "placeOrder"
method of the PetStore class, do not pass the Menagerie item directly to the
"checkAvailability" method of the inventory, and do not try to
remove the Menagerie object directly from the inventory.
Instead, use the Menagerie method "getAnimalList" to retrieve the
list of animals that make up the Menagerie, and then pass that list of
animals into these two methods.
Restrictions:
- You may not use any loops at all anywhere in
the Menagerie or PetStore classes. This will hopefully steer
you away from writing redundant code! (There is a loop in the toString
method of the Menagerie class, but there should be no loops anywhere else in
these two classes. There will be plenty of loops in the
SortedListOfImmutables class, though.)
- When elements are added to or removed from the SortedListOfImmutables,
the size of the internal array must end up the same as the number of items
that are currently in the list.
You may NOT have any extra "unused"
elements in your array after calls to either of these methods.
- The instance variables you will need for your classes are already
declared for you in the code -- you may not add any others.
- You may not use any static variables anywhere in this project.
- You may not use the operator instanceof
- You may not use any of the Java collections classes, such as ArrayList,
HashSet, LinkedList, etc.(In case you know what these are.)
- You may not call any static methods of the Collections class (in case
you know what that is.)
- You may not use any sorting algorithms at any time. The elements
of the lists must be inserted in the correct position to maintain the
alphabetical order of the list. You never sort the whole list.
- You are expected to use good style (as always), including commenting,
proper indentation, proper choice of variables names, etc.
Grading
Your grade will be computed as follows:
- Public Tests: 30%
- Release Tests: 65%
- Style: 5% (You will be penalized heavily for redundancy on
this project -- you could lose all 5 points.)
Web Accessibility