Practice Exam
Picnic Assignments: Courses and Foods

Problem Statement (Including Input and Output)

First, read a file of information about foods that need to be brought to a picnic, building a Map whose key is the first word on the line and whose value is a Set of all subsequent words on that line: from each course word to a Set of all foods for that course. All tokens are separated by one semi-colon character. For example, the input file picnic.txt contains the following lines:
appetizer;cheese;sardines
salad;caeser;macaroni
main;hamburgers;hot-dogs;veggie-burgers
drinks;milk;OJ
dessert;pie;cake;ice-cream;jello
side-dish;baked-potatoes
Here, for the drinks course there is milk and OJ.

Second, print a sorted version of this Map: the courses must be printed in alphabetical order, one per line, each followed -on the same line- by its Set of food. The food names don't have to be in alphabetical order.

Map (sorted alphabetically by course)
  appetizer: [sardines, cheese]
  dessert: [ice-cream, pie, cake, jello]
  drinks: [milk, OJ]
  main: [hamburgers, veggie-burgers, hot-dogs]
  salad: [macaroni, ceaser]
  side-dish: [baked-potatoes]

If you finish this part correctly, you will at least be awarded 50 points of the total 100 points that this entire problem is worth.

Third, process a file that contains requests for people coming to the picnic. Each line contains two tokens separated by a semi-colon. The first token is the person's name, while the second token is what course they want to bring (it will alwasy be one of the ones used to build the map).

If there are no foods of that course still available, the person will told that they are out of luck. If there are any foods of that course still available, the person will be told to bring one of those foods. Your program can select any food in the set: this is easy to do by choosing the first one when you iterate over the set; you could also create a list initialized by the set and then choose what is stored in the list at index 0 (since the constructor iterates over the set, it will most likely be the same value).

Remember that once someone brings a food, it is no longer available for others to bring, so remove it from the appropriate set.

The file requests.txt looks thus:

John;drinks
Mary;dessert
Joanne;drinks
Tim;appetizer
Kurt;side-dish
Joe;drinks
Katie;main
Sarah;main
Becky;drinks
Lana;main
Betty;side-dish
For each request, state what the person's name and whether they are out of luck (or what they should bring).

Finally, print out the remaining Map (in the sorted form in which it was first printed: for simplicity in the exam, just cut/paste your code). Note that there may be some courses with an empty set of foods at the end.

Sample Interaction

The program, as specified, will have the following interaction: user-typed information appears in italics. Your output should "match" this one (because of the randomness, different foods might be output, but always from the right category, and never repeated. Also, all the "out of lucks" should occur at the same spots.
Enter food file name: picnic.txt
Map (sorted alphabetically by course)
  appetizer: [sardines, cheese]
  dessert: [ice-cream, pie, cake, jello]
  drinks: [milk, OJ]
  main: [hamburgers, veggie-burgers, hot-dogs]
  salad: [macaroni, caeser]
  side-dish: [baked-potatoes]

Enter request file name: requests.txt
  John wants to bring drinks: will bring milk
  Mary wants to bring dessert: will bring ice-cream
  Joanne wants to bring drinks: will bring OJ
  Tim wants to bring appetizer: will bring sardines
  Kurt wants to bring side-dish: will bring baked-potatoes
  Joe wants to bring drinks: is out of luck
  Katie wants to bring main: will bring hamburgers
  Sarah wants to bring main: will bring veggie-burgers
  Becky wants to bring drinks: is out of luck
  Lana wants to bring main: will bring hot-dogs
  Betty wants to bring side-dish: is out of luck

Map (sorted alphabetically by course)
  appetizer: [cheese]
  dessert: [pie, cake, jello]
  drinks: []
  main: []
  salad: [macaroni, caeser]
  side-dish: []