Overview
This assignment is the second part of a two-week project that utilizes abstract classes, interfaces, and polymorphism to simulate an ecosystem of different organisms. Last week you created all of the plant and animal classes that will be present in the simulation. This week you will be creating the simulation program. Thanks to the groundwork that you created last week, we can use polymorphism to easily perform operations on all of our organism types. Additionally, we’ll be using ArrayLists to contain the constantly fluctuating number of organisms in our ecosystem.
The coding skills you will practice in this assignment include:
using polymorphism
downcasting objects to call their class methods
using ArrayLists
Instructions
Add a new static class called EnvironmentSimulation to the project that you started last week. This simulation will manage an ArrayList of Organisms – these are the plants and animals present in the ecosystem simulation. The simulation program must perform the following operations:
Have each Organism take their actions (do the following sub-steps in order for every Organism currently in the simulation)Have the Organism reproduce If the Organism is an Animal:Check if it is hungry. If so, have it eat other valid living Organisms until it is no longer hungry
Expend energy (only once)
If the Organism is a Plant:Have the plant regenerate
Add newly born Organisms to the simulation
Remove dead Organisms from the simulation
Display the status of the simulation which includes for each Organism species:How many of that species were already alive
How many of that species were just born
How many of that species have just died
The new total number for that species
You must not modify anything in the classes you created last week! Assuming your classes from last week were created according to the instructions, all operations you need are already present as methods. You must create the simulation program without adding any new methods to any of the organism classes.
The simulation must perform all of these operations once and then ask the user if they want to continue the simulation or quit. If they choose to continue, all of these operations repeat from the beginning. Each repetition of the simulation is a simulation “step”.
Details of the Simulation
1. All plants and animals are stored in a single ArrayList of OrganismsYou must store all of your Organisms in a single ArrayList of type Organism. This is possible because all plant and animal classes are derived from the Organism abstract class. If you need to perform specialized actions on each of your creatures, you must first check that they are an instance of the desired child class of Organism, and then downcast them to the appropriate type.
2. Not all Organisms are added at once in the beginningInstead of adding all of the Organisms in the simulation at the beginning, you must add each species separately after different amounts of time have passed. This allows the prey populations to become established before the predators, which makes the simulation more interesting to watch.
5 Orange Trees and 30 Grass Patches are added at the very beginning of the simulation.
30 Squirrels are added on the fifth (5) simulation step.
50 Deer are added on the tenth (10) simulation step.
10 Wolves are added on the twentieth (20) simulation step.
No Oranges should be added manually – they should be exclusively produced by the Orange Trees
3. Dead Organisms still take their actionsThe simulation does not prevent dead Organisms from reproducing or taking actions. The individual steps of our simulation do not take time into account. If dead Organisms were prevented from taking actions, then Organisms earlier in the ArrayList would be given priority. By allowing dead organisms to take their actions as normal, every single Organism is given equal priority.
4. What Organisms count as prey?An Animal object can only eat another Organism if all of the following are true:
The Organism is an instance of type Edible.
The Organism is valid prey for this Animal (canEat())
The Organism is alive. Even though dead Organisms can take actions, they still can’t be chosen to be eaten.
5. Organisms that were just born are not added to the simulation until after all existing Organisms have already actedAny Organisms that were born during the current simulation step do not take any actions during the step in which they were born, and they cannot be targeted as prey. Newly born Organisms are only added to the ArrayList of Organisms after the step in which they were born. You may want to keep a second ArrayList for these newly born Organisms and only combine the two lists once the current iteration has ended.
Submission
Test your simulation thoroughly before submission! You are welcome to tweak the numbers in the simulation to produce different behavior for testing, but please revert them to the values provided for each class before submission.
Your submission must include the following:
The EnvironmentSimulation static class
A screenshot of the simulation program’s output at step 20
All plant and animal classes used in the simulation, which are:Three abstract classes: Organism, Animal, and Plant
The Edible interface
Three animal species classes: Squirrel, Deer, and Wolf
Three plant species classes: GrassPatch, Orange, and OrangeTree
For this assignment, please compress all of your files into a single zip file! Please only include your class files and screenshot in the zip file – do not include any other files from the Eclipse project.
To create a zip file:
Place all of your class files into a single folder on your computer. For Windows computers, right click the folder and select “Send to > Compressed (zipped) folder” from the menu. For Mac computers, control-click the folder and select “Compress” from the menu.
A new .zip folder will be created with the same name as the original folder. This is the zip file that you submit.
When you have completed all of the files and compressed them into a zip file, submit the zip file by clicking “Start Assignment” at the top of the page and then selecting your file for submission. This assignment will only accept a .zip file; it will NOT accept an Eclipse project file or the files individually. No points will be awarded to programs that do not compile.
Rubric
Important - Read this before proceeding
These instructions reflect a task our writers previously completed for another student. Should you require assistance with the same assignment, please submit your homework details to our writers’ platform. This will ensure you receive an original paper, you can submit as your own. For further guidance, visit our ‘How It Works’ page.