Assignment 3
Be sure to type up your answers so you can submit them electronically on the
BlackBoard Connect system. You may complete this assignment individually.
Make sure all your files have your full name and student number on it.
Type up your answers using Eclipse.
The file format of the Java program you are to submit must be .java.
This assignment is marked out of 63 points.
Due Date
March 29, 2014, 11:59AM (just before noon).
24 Hour Silence Policy
Due to the large class size and the potential volume of questions, we are
implementing a 24-hour silence policy. This means that any questions posted on
the discussion forum in the 24 hours immediately preceding the assignment
deadline may not get answered in time. This does not mean that we will
stop answering questions the moment the day before the deadline arrives, it just means
that we cannot promise all the questions will be answered in time, due to our
prior engagements, such as other classes and meetings we have.
For this reason, please be sure to attempt the assignment early, and try to
complete it as if it were due two days prior to the real deadline.
In any case, we will try to answer all the questions that show up on the
discussion forum. Note that questions sent to emails will not be
answered, as we want all course related material to be viewed for everyone's
benefit.
What You Are Given
There are 2 questions in this assignment. The first question is to practice
queues and stacks, and the second is to practice sorting and search. These
questions will also include a review of several core concepts of this course.
Question 1 [23 points]
For this question, you are going to build a simple word processor that takes
input from the user (words), "remembers" them up, monitors for user command
for undoing certain words, and monitors for user command for printing the
stored words into a file. For the time being, we want to keep the program
simple by taking the user out of the problem, so that your task is to build
the core functionality of the word processor for this question only. Doing
this will also facilitate testing. In the very last part, you can add the user
back into the problem and make sure the rest of your code still works.
You are given an interface in WordProcessorInterface.java that
specifies the methods needed for a basic word processor. Make sure you read
the comments so you implement the methods according to the specifications.
Be sure to submit the output from your regular tests in WPOutput.txt and the
file output in WP-FileOutput.txt for this question as well.
Question 2 [40 points]
In this question, you will create a tournament of animals that will battle in
an arena, similar to Pokemon. There will be a total of 8 competitors in this
single-elimination tournament. This question will get you to practice
inheritance and polymorphism, as well as sorting and search.
(Note: We do not condone the harming of animals.)
Specifically, complete the following parts:
- Part 1 12 points:
- Download the template for the Animal
class that serves as a parent class to four different subclasses of animals,
which you will define later.
- 1 point - Finish the injure() method as follows:
Subtract the amount of damage from the animal's health.
If it drops below 0 set isAlive to false, indicating the animal has
fainted.
- 2 points - Finish the attack() method as follows:
Randomly generate an amount of damage (ranging from 0 to the strength of the
animal) which will be inflicted on a target animal, using the target's
injure() method. Add the amount of damage done to the score.
Print out a summary of the attack, e.g. "Jack hits Fred for 23 damage."
Check if the target has fainted. If it has, print that the target has fainted.
- 1 point - Finish the toString() method as follows:
Return a meaningful summary of the animal, e.g., "Jack the Bear
(GrizzlyBear, 90 Strength, 144 points)".
- Next, create four different subclasses of animals. Give each animal a
minimum and maximum strength value according to your own wishes. For
example, a Grizzly Bear would have a higher max strenth than a Dog. (Don't
go below 0 or above 100).
- 8 points total, 2 per subclass - Initialize each animal subclass
by calling super() to the Animal class. Randomly generate a
strength value (between the min and max strengths allowed for this animal)
and use a parent method to overide this animals strength attribute.
Set the type attribute of this Animal to be the name of the class you called
this animal, using a super method. For instance, a GrizzlyBear animal will
have a type of "Grizzly Bear".
See the sample GrizzlyBear.java
subclass to get started.
- Part 2 10 points:
- Download the template for the Arena class
that serves as the battle grounds for each stage of the tournament.
- 2 points - In the constructor, initialize the two competitors, the
arena name, print the tale of the tape, and then start the battle.
- 1 point - In the taleOfTheTape() method, print a
meaningful pre-fight summary of the battle. Remember that toString()
method you wrote in the Animal class? Use it here.
See the sample output for additional guidance.
- 4 points - In the startBattle() method, pick a way to
determine who attacks first each turn. This can be done randomly, or you can
create your own way to do this (i.e whichever animal has less strength). It's
really up to you how you do this.
Once you know who attacks first, have the first animal attack the second
animal using its attack() method.
Then have the second animal attack the first animal. However, after each
attack check if the target of the attack has fainted (when isAlive is
false).
Repeat this process as long as both competitors are alive. Once an animal has
fainted, end the battle, store the winner and loser, and print the results.
Heal the winner using it's healUp() method, and award it bonus points
for winning the battle.
- 1 point - In the printResults() method, print a meaningful
post-fight summary of the battle. Say who wins, and provide the score of each
competitor.
See the sample output above for additional guidance.
- Part 3 18 points:
- Download the template for the Tournament class which will decide the
winner among the 8 participants.
- 2 points - In the constructor, initialize the competitors array
using an array of Animals as input (assume the input array always has exactly
8 animals in it). Initialize each quarterfinal arena using two competitors
from your competitors array. Initialize each semifinal arena using the winners
of your quarterfinal arenas. Initialize the finalRound using the winners of
your semifinal arenas. Print the results of the tournament using the method
that you will create in the next step. Award the consolation prize using the
awardConsolation() method you will create later.
- 1 point - In the printResults() method, call
sortResults() and print each competitor in order with a loop.
- 8 points - In sortResults(), use insertion sort to sort
the array of competitors by score, from highest to lowest. If there is a tie,
sort by their strength.
- 3 points - After sorting the results, generate a random number
bewteen 0 and 300. Use binary search to find the animal with the closest score
to that number, and award them with a consolation prize with text. For
instance, if Grass Lover has the closest score to the generated number, print
"Grass Lover awarded the consolation prize."
See the sample output above for additional guidance.
- Part 4 4 points:
- Download the template for the TournamentTest class to ensure
everything works properly.
- 2 ponts - Initialize 8 different animal cometitors, two of each
subclass you created. Give them unique names. Place them all into an animal
array. Run a tournament with the competitors array as it's input.
- 2 points - Provide the output of your tournament in a text file
called TournamentOutput.txt, and submit this as well. It should look similar
to the sample output provided.
What to Submit
Be sure to comment all the methods and attributes for clarity.
For this assignment, submit the following:
- WordNode.java
- WordProcessor.java
- TestWordProcessor.java
- WPOutput.txt
- WP-FileOutput.txt
- Animal.java
- All Four Animal Subclasses
- Arena.java
- Tournament.java
- TournamentTest.java
- TournamentOutput.txt
- Include your full name and student ID.
- List the full names of the people who helped you in this assignment
(include students and TAs if applicable), and mention what they helped you with
-- failure to do so honestly will result in a lower mark and may be reported
for academic discipline