Lab 3 - Fortune Cookies
Due: Wednesday February 14th at 11:59 PM

Required Files

Please download lab3.zip to get started.

Overview

Since the 1970s, computer users have been entertained by cookie-style fortunes. The original program can still be enjoyed today -- just type "fortune" on the command line.

This lab asks you to implement your own fortune-telling program. In the process you are introduced to linked lists.

The Nitty Gritty

The program consists of two classes:

FortuneCookie.java

You'll need to complete the constructors, the getters, a toString(), an equals(), and a compareTo(). If you need a reminder about Comparables, please refer to the Java API documentation.

In order to offer the fortunes in a random order, you will generate an array of lucky numbers using the Random class. For example, if r is an instance of Random, r.nextInt(100), gives a random number between 0 and 99.

FCLinkedList.java

FCLinkedList is the meat of the assignment. We learned about LinkedLists this past week; now is the time to put all that knowledge into action. You should complete the constructor and size(), as well as add(), which adds a cookie at a specified position in the linked list

Fortune.java
This class houses the main(). It basically handles all user interaction. It need not be elaborate. It should work from the command line and allow the user to

  1. add a fortune
  2. peek at a fortune
  3. look at a user-specified fortune in the list
  4. grab the first fortune from the top,
  5. remove a specific fortune at a user-specific index
  6. count the number of fortunes they have
  7. print out all the fortunes
  8. quit the fortune machine.

Fortune.txt

This is just a list of sample fortunes that you can use to create your fortune cookies with. Feel free to use different ones.

Plan of Attack

  1. Complete FortuneCookie.java.
  2. Compile and test your code! If there are problems, now is the time to fix them. Don't move on to FCLinkedList if FortuneCookie is broken.
  3. Complete FCLinkedList.java.
  4. Compile and test your code some more!
  5. Complete Fortune.java.
  6. Test your code some more! You should now have a working Fortune program that gives you fortunes, allows you add them, remove them, and check how many you have. If you don't, see the beginning of this step. Good luck, and happy fortunes!