Assignment 2: Baba Yaga's Chickens
University of Toronto, St. George Campus
Due at the beginning of your tutorial.
Worth 8% of the Course Grade
Introduction
Deep in the middle of the forest lives Baba Yaga, the wicked witch. Legends report that her hut wanders about on chicken legs, that her geese eat little children, and that her fence has a human skull on each plank but one. It is a lesser-known fact that Baba Yaga's most prized possession are her seven chickens. Three of them lay golden eggs; the other four can peck so viciously that three bites from them will kill a strong person. But in the darkness of the coop, the good chickens and the bad chickens all look alike.
Despite the danger, two thieves attempt to steal the good chickens. To do so, they must search through the chicken coop by touching whatever chickens they think are good chickens.
Here's how the game works:
Summary
Your task for this assignment will be to write a java program that models several attempts by the two thieves to steal Baba Yaga's chickens. The program is an opportunity to practice what you know about the String class and its methods, I/O, conditional statements, loops, and style.
The program represents the chicken coop as a String of seven characters: "abcdefg". At the beginning, it takes a String as input. If the String is "quit", then the program terminates. Otherwise, assume that the user has entered a three-character String, with characters ranging from a to g (e.g. "bdf"). The three characters indicate the good chickens. Then, the program runs for several rounds. At every round, each of the two thieves touches a chicken and suffers the consequences. A message is printed out to indicate what has happened to each thief. If one of the thieves wins, the program prints out a message indicating who won this game.
Then the program prints out a message to the user asking for the next String. The program will thus run games until the user enters "quit". See the sample output for some examples of the program's output.
What To Do
Part A: Designing an object-oriented program -- due
at beginning of tutoiral on July 5
(worth 2% of the course mark).
Part A is the design of your program. You must hand in the description of the classes you'll be using in the assignment. Each description must contain: class name; instance variables; method names with comments. You are allowed to change these classes later on, when you actually write the program, but the descriptions themselves must make sense for you to get the Part A marks.
Examples of two such class descriptions:
1) Class name: Airport (the main class)
Instance variables: none
Methods: main
2) Class name: Airplane
Instance variables:Methods:
- name of plane -- String;
- number of passagers -- int;
- speed -- double;
- name of airline -- Airline.
- set and get methods for each of the instance variables
- increaseSpeed: increases the speed by a given factor
- addPassengers: adds a given number of passengers
How do you come up with these descriptions? Here's a procedure that you may follow if you find it helpful.
Part B: Writing the Code -- due at beginning of
tutorial on July 19
(worth 6% of the course mark)
Implement the code; that is, create a program using the classes you have designed. You may not use either Vectors or arrays. All assignments using Vectors or arrays will receive 0 for the code.
Make sure you write your program according to the stylistic conventions discussed in class (no magic numbers, proper variable names, etc.). It's very important to comment your code properly, according to the indications that you'll receive in class. Do not forget to comment all instance variables and all method headers, in addition to tricky spots inside the method bodies, and the top of each class file. A good part of your mark will depend on the design and the style of your program. Refer to the "How to do well on an assignment" section of the Doing your work in CSC108H web site for more information.
Finally, test your program with the following combinations of good chickens:
1) Testing the positioning of the good chickens
2) Testing the outcomes of the game
Print out the results and hand them in as well. Make sure you highlight the results for each game. Note that you'll lose a lot of marks if you don't hand in your output.
What to Hand In
For this assignment, you must submit the files containing your code on a 3.5" floppy diskette. You must label your diskette with your name and student number.
On paper, you need to submit your code, main class first, and your output, with test cases in the order given in the handout (please label it as "output" and highlight the result of each test case).
Put your printouts and your floppy diskette into an 8.5x11" unsealed envelope; fasten the completed cover page to the outside of the envelope, and hand the envelope in to your TA.