Commit eaa41559 authored by a-j.towse's avatar a-j.towse

final commit with all working methods and comments to show

parent e893fdc4
No preview for this file type
import java.util.ArrayList; import java.util.ArrayList;
public class Zoo { public class Zoo {
//Stores a list of animals within the zoo
private ArrayList<Animal> animalArrayList= new ArrayList<>(); private ArrayList<Animal> animalArrayList= new ArrayList<>();
public ArrayList<Animal> getanimalArrayList(){ public ArrayList<Animal> getanimalArrayList(){
...@@ -21,12 +22,14 @@ public class Zoo { ...@@ -21,12 +22,14 @@ public class Zoo {
System.out.println(animal.getFoodType()); System.out.println(animal.getFoodType());
} }
//displays the food required for all animals in an ArrayList
public void displayfoodListRequirements(ArrayList<Animal>animalList){ public void displayfoodListRequirements(ArrayList<Animal>animalList){
for (int i=0; i < animalList.size();i++){ for (int i=0; i < animalList.size();i++){
System.out.println(animalList.get(i).getFoodType()); System.out.println(animalList.get(i).getFoodType());
} }
} }
//displays the details of a single animal
public void displayDetails(Animal animal){ public void displayDetails(Animal animal){
ArrayList<String> detailList=animal.getDetails(); ArrayList<String> detailList=animal.getDetails();
for(int i = 0; i < detailList.size();i++){ for(int i = 0; i < detailList.size();i++){
...@@ -34,12 +37,14 @@ public class Zoo { ...@@ -34,12 +37,14 @@ public class Zoo {
} }
} }
//displays the details of each animal in an arrayList
public void displayListDetials(ArrayList<Animal>animalList){ public void displayListDetials(ArrayList<Animal>animalList){
for (int i=0; i < animalList.size();i++){ for (int i=0; i < animalList.size();i++){
displayDetails(animalList.get(i)); displayDetails(animalList.get(i));
} }
} }
//displays all animals from a specific environment
public void displayEnvironmentList(String environment){ public void displayEnvironmentList(String environment){
for (int i=0; i < animalArrayList.size();i++){ for (int i=0; i < animalArrayList.size();i++){
if(animalArrayList.get(i).getEnvironment() == environment){ if(animalArrayList.get(i).getEnvironment() == environment){
...@@ -48,20 +53,25 @@ public class Zoo { ...@@ -48,20 +53,25 @@ public class Zoo {
} }
} }
//WIP animal type, get class //creates and displays an arrayList of animals of a particular type
public void displayAnimalType(String animalType){ public void displayAnimalType(String animalType){
ArrayList<Animal> typeArrayList = new ArrayList<>();
for (int i=0; i < animalArrayList.size();i++){ for (int i=0; i < animalArrayList.size();i++){
if(animalArrayList.get(i) instanceof Mammal && animalType == "Mammal"){ if(animalArrayList.get(i) instanceof Mammal && animalType == "Mammal"){
System.out.println(animalArrayList.get(i).getName()); System.out.println(animalArrayList.get(i).getName());
typeArrayList.add(animalArrayList.get(i));
} }
if(animalArrayList.get(i) instanceof Bird && animalType == "Bird"){ if(animalArrayList.get(i) instanceof Bird && animalType == "Bird"){
System.out.println(animalArrayList.get(i).getName()); System.out.println(animalArrayList.get(i).getName());
typeArrayList.add(animalArrayList.get(i));
} }
if(animalArrayList.get(i) instanceof Reptile && animalType == "Reptile"){ if(animalArrayList.get(i) instanceof Reptile && animalType == "Reptile"){
System.out.println(animalArrayList.get(i).getName()); System.out.println(animalArrayList.get(i).getName());
typeArrayList.add(animalArrayList.get(i));
} }
if(animalArrayList.get(i) instanceof Fish && animalType == "Fish"){ if(animalArrayList.get(i) instanceof Fish && animalType == "Fish"){
System.out.println(animalArrayList.get(i).getName()); System.out.println(animalArrayList.get(i).getName());
typeArrayList.add(animalArrayList.get(i));
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment