CSIT 254 – Project 2 “Hints”
The first hint is from the Project 2 sheet. A sample program that has ‘structure’ of ‘Menu’ and
‘commands’: DemoDoWhileStrings.java in Canvas Module: Code Library and file
CISY254JavaReviewContinued.zip
•
•
The ‘commands’ for Project 2 such as A for add and D for display can replace customer choices
like Sundae and Cone
The “display” of the recipe can be replaced with the logic for the command
Bag of cars: GenericLinkedBagSimpleTestVer5.java in Programming Lab 5 Generic.
•
In that file, line 20 is a declaration of a linked bag of objects
•
Also, in that file, lines 233-255 are a static method called displayLinkedBagCarAndSize of which
the body of the method uses the iterator() from the LinkedBag to display the contents.
1
CSIT 254 – Project 2 “Hints”
•
Note: to use a class with LinkedBag it has to be a Comparable class. The Car.java that is in the
Programming Lab 5 Generic is comparable
o Line 10 has the class header
o
Lines 112-124 has the compareTo() method
For commands ‘A’,’F’,’R’, you need to prompt the user for values for the attributes. You did input in the
driver for Project 1, but if you also look at PizzaCompare.java in Canvas Module: Code Library and file
CISY254ClassReview.zip
•
Line 26-33 get input from user
•
Lines 36-37 instantiates an object.
•
Suppose we had a bag of Pizza, then
pizzaBag.add(new Pizza(sizeEntered,numToppingsEntered,toppingDescriptionEntered));
would add a pizza to the bag
The last hint is that there is a hint on the Project 2 sheet.
For the “find” you would have prompts prior to the if to get values from the user.
2
CSIT 254 – Project 2 – Linked List of Generic Objects
Create a program that allows a user to maintain a “Bag” of “Objects” using your Class from Project 1 and
your Node, LinkedBag (may be called SinglyLinkedList), and Lister from Lab 5.
Regarding your class:
●
You will have to add an equals() method to your Class so that exists(), remove() and
countOccurrences() in LinkedBagwill work
● You will have to add a compareTo() method to your class so that add() works [note: the Car class
compares year first and make second..’so a 1965 Shelby is before a 1973 Le Mans, and a 2017
Acura is before a 2017 Buggati ]
● Since for displaying from the driver the iterator() from the LinkedBag will be used, your driver
must use the getters for displaying the object.
● You may need to add a constructor that accepts ALL parameters to make the call of to the
methods easier.
example: after prompting user for yearEntered and makeEntered, you then can execute:
if (myBag.exists(new Car(yearEntered,makeEntered)))
● If you have to tweak your class because of feedback on Project 1, your revised class is subject to
the same requirements as Project 1 including exclusions so please update it based on my
comments back to you.
Your program should have the following options:
●
●
●
●
●
●
●
A – Add “Object” to bag
o Asks the user to enter attributes for an “Object” and then adds the “Object” to the bag
(calls .add() method which maintains order)
R – Remove “Object” from bag
o Asks the user to enter attributes for an “Object” and then attempts to remove the
“Object” from the bag – should return a success/failure message (calls .remove()
method – need to use if for success/failure) …the remove should maintain order on
remove()
F – finds if an “Object” is in the bag
o Asks the user to enter attributes for an “Object” and then a message based on whether
the object is in the bag (calls exists() method)
D – displays contents of bag and the total number of items in the bag (this will use the iterator()
and then the getters from the object pulled from the list))
X – gracefully exits
Note: if user selects an invalid command – display an error
Your program should follow the output format that I have listed below including blank lines.
Even if your class is different, the output format should be the same.
1
CSIT 254 – Project 2 – Linked List of Generic Objects
Grading Rubric
Node, LinkedBag, your Class (60 points):
●
Each File:
o Comment with name (1 pt each file = 3 pts)
o Javadoc comments each file for constructors and methods (8 pts each file 24 points)
o Fields (2 pts each file = 6 pts)
o Appropriate Constructors (2 pts each file = 6 pts)
o Methods(setters/getters) between 2 files: ( 20 pts)
o deductions for improper naming guidelines (Classes, methods, and identifiers
o deductions for improper indenting (methods indented inside class, statements indented
inside method, conditionally executed code indented)
o deductions for improper organization of your Classes ( instance variables up top /
Constructor(s) / setters/getters )
o Remember projects must compile and run or else it is a 0
o Remember projects must be submitted on time or else it is a 0
Program that Interacts with user (55 points)
● Comment in program with name (2 points)
● Creation of LinkedBag of objects [ Hint see GenericLinkedBagSimpleTestVer4.java line 19]
(2 points)
● Sentinel controlled loop based on String [ programs looping on numbers only will not be
accepted and receive a 0, programs that contain while True will not be accepted and receive a
0] (4 points)
● Displaying menu of options (2 points)
● Accepting String command from user(2 points)
● A-prompting user for attributes and adding to LinkedBag (5 points)
● R-prompting user for attributes and attempting to remove from LinkedBag and displaying
success/failure of removal (5 points)
● F-prompting user for attributes. Check if object exists in LinkedBag using exists() (3 points)
● D-display contents of LinkedBag and size[ hint – see the displayLinkedBagCarAndSize() method in
the GenericLinkedBagSimpleTestVer4.java file ] (2 points)
● X-gracefully exit on request [ programs that stop looping for invalid commands will not be
accepted] (3 points)
● Error message when command is not recognized (2 points)
● following the naming guidelines for Classes and identifiers (8 points)
2
CSIT 254 – Project 2 – Linked List of Generic Objects
●
●
●
●
proper indenting (methods indented inside class, statements indented inside method) (5 points)
organization of your Class( instance variables up top / Constructor / setters/getters ) (5 points)
Remember projects must compile and run or else it is a 0
Remember projects must be submitted on time or else it is a 0
This ‘Test Script’ will be used to test your program.
Test Script:
Test Case
On start (empty bag)
Bad command
Display
Remove
Exists
Add 1
Display
4 more adds
with 2 duplicates
Display
Exists non-existent
Exists existent-1
Exists existent-2
Remove non-existent
Display
Remove existing item
Display
X
Expected Results
Comments
invalid
empty message
can’t remove
Not there
prompts for attributes
item visible, size 1
5 items (ordered)
Not there
there
there
not removed
5 items, size 5
removed
4 items, size 4
graceful exit
3
CSIT 254 – Project 2 – Linked List of Generic Objects
Sample Run :
run:
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: p
Invalid Selection
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: d
Soda Bag: [–Empty–]
Size: 0
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: r
Enter name of soda to remove from bag: 7up
Enter price of soda to remove from bag: 2
Enter calories of soda to remove from bag: 56
oops 7up with 56 calories @2.00 not Removed!
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: f
Enter name of soda to find in bag: 7up
Enter price of soda to find in bag: 2.00
Enter calories of soda to find in bag: 56
7up with 56 calories @2.00 is not in the bag
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
4
CSIT 254 – Project 2 – Linked List of Generic Objects
D – Display Contents of Bag
X – Exit
Enter Selection: a
Enter name of soda to add to bag: Mountain Dew
Enter price of soda to add to bag: 1.8
Enter calories of soda to add to bag: 239
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: d
Soda Bag: [{Mountain Dew 239 $1.80}]
Size: 1
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: a
Enter name of soda to add to bag: Pepsi
Enter price of soda to add to bag: 1.7
Enter calories of soda to add to bag: 876
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: a
Enter name of soda to add to bag: Coke
Enter price of soda to add to bag: 1.99
Enter calories of soda to add to bag: 456
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: a
Enter name of soda to add to bag: Mountain Dew
Enter price of soda to add to bag: 1.8
Enter calories of soda to add to bag: 239
Bag of Sodas
5
CSIT 254 – Project 2 – Linked List of Generic Objects
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: a
Enter name of soda to add to bag: Dr Pepper
Enter price of soda to add to bag: 2.20
Enter calories of soda to add to bag: 176
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: d
Soda Bag: [{Coke 456 $1.99}, {Dr Pepper 176 $2.20}, {Mountain Dew 239 $1.80},
{Mountain Dew 239 $1.80}, {Pepsi 876 $1.70}]
Size: 5
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: f
Enter name of soda to find in bag: 7up
Enter price of soda to find in bag: 1.23
Enter calories of soda to find in bag: 345
7up with 345 calories @1.23 is not in the bag
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: f
Enter name of soda to find in bag: dr pepper
Enter price of soda to find in bag: 2.2
Enter calories of soda to find in bag: 176
dr pepper with 176 calories @2.20 is in the bag
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
6
CSIT 254 – Project 2 – Linked List of Generic Objects
Enter Selection: f
Enter name of soda to find in bag: mountain DEw
Enter price of soda to find in bag: 1.80
Enter calories of soda to find in bag: 876
mountain DEw with 876 calories @1.80 is not in the bag
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: f
Enter name of soda to find in bag: mountain DEw
Enter price of soda to find in bag: 1.80
Enter calories of soda to find in bag: 239
mountain DEw with 239 calories @1.80 is in the bag
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: r
Enter name of soda to remove from bag: 7up
Enter price of soda to remove from bag: 1.23
Enter calories of soda to remove from bag: 234
oops 7up with 234 calories @1.23 not Removed!
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: d
Soda Bag: [{Coke 456 $1.99}, {Dr Pepper 176 $2.20}, {Mountain Dew 239 $1.80},
{Mountain Dew 239 $1.80}, {Pepsi 876 $1.70}]
Size: 5
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: r
Enter name of soda to remove from bag: dr pepper
7
CSIT 254 – Project 2 – Linked List of Generic Objects
Enter price of soda to remove from bag: 2.2
Enter calories of soda to remove from bag: 176
dr pepper with 176 calories @2.20 Removed!
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: d
Soda Bag: [{Coke 456 $1.99}, {Mountain Dew 239 $1.80}, {Mountain Dew 239 $1.80},
{Pepsi 876 $1.70}] Size: 4
Bag of Sodas
A – Add ‘Soda’ to bag
R – Remove ‘Soda’ from bag
F – Find ‘Soda’ in bag (exits)
D – Display Contents of Bag
X – Exit
Enter Selection: x
Bye!
BUILD SUCCESSFUL (total time: 5 minutes 40 seconds)
8