Question
Task 4 - Week Cycle Your fourth task is to write the code that will cycle through all 7 days of the week (Monday-Sunday), and
Task 4 - Week Cycle
Your fourth task is to write the code that will cycle through all 7 days of the week (Monday-Sunday), and each day print the status of all animals in the zoo and ask the user to select what item they want to give to each animal.
You will need to implement the following public method inside the VirtualZoo
class:
weekCycle(ArrayList zooAnimals)
This method should carry out the following set of operations for each day of the week (7 days in total).
- Print the message "The current day is X", where X should be the current day of the week (Monday, Tuesday, Wednesday Thursday, Friday, Saturday or Sunday)
- Print the status of each animal in zooAnimals. This can be done by calling the toString() method on each animal in the ArrayList.
- Ask the user what item they want to give to each animal in zooAnimals that is still alive, using the previously defined askItem(Animal animal) method. The user should not be asked to give an item to any animal that has died.
Once the week has concluded, the method should print the message "Total week cost = $X", where X is the value of the totalCost static variable inside the VirtualZoo
class.
You can test your code for this task by replacing beginSimulation() method in the VirtualZoo
class with the following updated version:
public void beginSimulation() { displayWelcome(); ArrayList
This will allow you to run the program from the VirtualZooDriver
class and complete the application from start to finish, with the exception that all animals will be treated the same regardless of their species.
Your output might look something like the following (user input in bold highlighted text):
+----------------------------------------------------------------------+ | Welcome to the Virtual Zoo! | | Use this application to simulate running a zoo with many animals | | This program is intended for zoo employees only | +----------------------------------------------------------------------+ How many animals are at your zoo? 2 What is the name of animal #1? Snowy What is the species of Snowy? monkey What is the name of animal #2? TIM What is the species of TIM? Bat That is not a valid species What is the species of TIM? GIRAFFE The current day is Monday Name = Snowy Species = Monkey Hunger = 50 Thirst = 50 Boredom = 50 Name = TIM Species = Giraffe Hunger = 50 Thirst = 50 Boredom = 50 What item would you like to give to Snowy? food What item would you like to give to TIM? sleep That is not a valid item What item would you like to give to TIM? toy The current day is Tuesday Name = Snowy Species = Monkey Hunger = 20 Thirst = 65 Boredom = 65 Name = TIM Species = Giraffe Hunger = 65 Thirst = 65 Boredom = 20 What item would you like to give to Snowy? toy What item would you like to give to TIM? WATER The current day is Wednesday Name = Snowy Species = Monkey Hunger = 35 Thirst = 80 Boredom = 35 Name = TIM Species = Giraffe Hunger = 80 Thirst = 35 Boredom = 35 What item would you like to give to Snowy? water What item would you like to give to TIM? toy The current day is Thursday Name = Snowy Species = Monkey Hunger = 50 Thirst = 50 Boredom = 50 Name = TIM Species = Giraffe Hunger = 95 Thirst = 50 Boredom = 5 What item would you like to give to Snowy? food What item would you like to give to TIM? toy You cannot give the same item as yesterday What item would you like to give to TIM? water TIM has died The current day is Friday Name = Snowy Species = Monkey Hunger = 20 Thirst = 65 Boredom = 65 Name = TIM (Dead) Species = Giraffe Hunger = 110 Thirst = 20 Boredom = 20 What item would you like to give to Snowy? toy The current day is Saturday Name = Snowy Species = Monkey Hunger = 35 Thirst = 80 Boredom = 35 Name = TIM (Dead) Species = Giraffe Hunger = 110 Thirst = 20 Boredom = 20 What item would you like to give to Snowy? water The current day is Sunday Name = Snowy Species = Monkey Hunger = 50 Thirst = 50 Boredom = 50 Name = TIM (Dead) Species = Giraffe Hunger = 110 Thirst = 20 Boredom = 20 What item would you like to give to Snowy? water You cannot give the same item as yesterday What item would you like to give to Snowy? food Total week cost = $1330
REPORT TASK
Answer the following questions:
- Describe what difference having the totalCost variable as static makes to your program.
- Describe what changes need to be made to your program in order for the user to manage multiple zoos with their own separate animals and costs.
Task 5 - Animal Species
Your final tasks is to implement the different effects and costs that the available items have on each animal species. First convert the Animal class into an abstract class, and the methods giveFood(), giveWater() and giveToy() into abstract methods. Create five new classes called Tiger
, Giraffe
, Hippo
, Panda
and Monkey
, which extend the Animal
abstract class. Each of these new classes should override the giveFood(), giveWater() and giveToy() abstract methods with their own species-specific implementations (as defined in the original Specification table). You will also need to modify the askAnimalSpecies method in the VirtualZoo
class to call the constructors of these five new classes.
Once this final task has been completed, your program should produce the complete example output provided with the original specifications.
REPORT TASK
Answer the following questions:
- Is there an alternative way that we could determine the species of an Animal object without calling the getSpecies() method?
- What impact does making the
Animal
class an abstract class have on our program? - What difference would making the
Animal
class an interface, instead of an abstract class, have on our program? - The zoo has asked you to write a Graphical User Interface for the program you have written. Could it be used as is, or would you need to rewrite parts of the code to accomplish this? Discuss and explain.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started