Commit b7652c30 authored by oscar.harding's avatar oscar.harding

Add new file

parents
package Animal;
import java.util.*;
public class animal {
public String name; // The animal's name e.g. "Bob"
public String type; // The animal's type e.g. "Mammal"
public String eats; // What it likes to eat e.g. "Worms"
public String species;//The animals' specific species e.g. "Monkey"
public String habitat;//The animal's habitat-desert,jungle etc.
public animal(String name, String species, String eats, String type, String habitat){
this.name = name;
this.species = species;
this.eats = eats;
this.type = type;
this.habitat = habitat;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//Creating the animals of the zoo
animal monkeyMike = new animal("Chip","Chimpanzee","Banana","Mammal","Jungle");
animal giraffeGina = new animal("Gina","Giraffe","Leaves","Mammal","Savannah");
animal parrotPolly = new animal("Polly","Parrot","Nuts","Bird","Jungle");
animal penguinPeter = new animal("Peter","Penguin","Fish","Bird","Arctic");
animal crocodileCaitlin = new animal("Caitlin","Crocodile","Livestock","Reptile","Swamp");
animal geckoGary = new animal("Gary","Gecko","Flies","Reptile","Jungle");
animal dolphinDave = new animal("Dave","Dolphin","Shrimp","Fish","Salt Water");
animal parrotfishPeter = new animal("Peter","Parrotfish","Kelp","Fish","Salt Water");
//This could definitely be done more efficiently but I couldn't work out how
//creating an arraylist of characteristics for each animal
//the "A" stands for Array
ArrayList<String> AmonkeyMike = new ArrayList<String>();
AmonkeyMike.add(monkeyMike.name);
AmonkeyMike.add(monkeyMike.species);
AmonkeyMike.add(monkeyMike.eats);
AmonkeyMike.add(monkeyMike.type);
AmonkeyMike.add(monkeyMike.habitat);
ArrayList<String> AgiraffeGina = new ArrayList<String>();
AgiraffeGina.add(giraffeGina.name);
AgiraffeGina.add(giraffeGina.species);
AgiraffeGina.add(giraffeGina.eats);
AgiraffeGina.add(giraffeGina.type);
AgiraffeGina.add(giraffeGina.habitat);
ArrayList<String> AparrotPolly = new ArrayList<String>();
AparrotPolly.add(parrotPolly.name);
AparrotPolly.add(parrotPolly.species);
AparrotPolly.add(parrotPolly.eats);
AparrotPolly.add(parrotPolly.type);
AparrotPolly.add(parrotPolly.habitat);
ArrayList<String> ApenguinPeter = new ArrayList<String>();
ApenguinPeter.add(penguinPeter.name);
ApenguinPeter.add(penguinPeter.species);
ApenguinPeter.add(penguinPeter.eats);
ApenguinPeter.add(penguinPeter.type);
ApenguinPeter.add(penguinPeter.habitat);
ArrayList<String> AcrocodileCaitlin = new ArrayList<String>();
AcrocodileCaitlin.add(crocodileCaitlin.name);
AcrocodileCaitlin.add(crocodileCaitlin.species);
AcrocodileCaitlin.add(crocodileCaitlin.eats);
AcrocodileCaitlin.add(crocodileCaitlin.type);
AcrocodileCaitlin.add(crocodileCaitlin.habitat);
ArrayList<String> AgeckoGary = new ArrayList<String>();
AgeckoGary.add(geckoGary.name);
AgeckoGary.add(geckoGary.species);
AgeckoGary.add(geckoGary.eats);
AgeckoGary.add(geckoGary.type);
AgeckoGary.add(geckoGary.habitat);
ArrayList<String> AdolphinDave = new ArrayList<String>();
AdolphinDave.add(dolphinDave.name);
AdolphinDave.add(dolphinDave.species);
AdolphinDave.add(dolphinDave.eats);
AdolphinDave.add(dolphinDave.type);
AdolphinDave.add(dolphinDave.habitat);
ArrayList<String> AparrotfishPeter = new ArrayList<String>();
AparrotfishPeter.add(parrotfishPeter.name);
AparrotfishPeter.add(parrotfishPeter.species);
AparrotfishPeter.add(parrotfishPeter.eats);
AparrotfishPeter.add(parrotfishPeter.type);
AparrotfishPeter.add(parrotfishPeter.habitat);
//Creating an arraylist of the animal characteristic arrays, to search through.
ArrayList<ArrayList<String>> animals = new ArrayList<ArrayList<String>>();
animals.add(AmonkeyMike);
animals.add(AgiraffeGina);
animals.add(AparrotPolly);
animals.add(ApenguinPeter);
animals.add(AcrocodileCaitlin);
animals.add(AgeckoGary);
animals.add(AdolphinDave);
animals.add(AparrotfishPeter);
//Displaying the details of an individual animal
System.out.println("Display the details of an individual animal:");
System.out.println(AmonkeyMike);
System.out.println();
//Displaying the details of each animal together in an arraylist
System.out.println("Display the details of each animal in an arraylist:");
System.out.println(animals);
System.out.println();
//Creating an arraylist to fill with a particular animal type, mammals in this instance
ArrayList<String> Mammals = new ArrayList<String>();
for (int counter = 0; counter < animals.size(); counter++) {
for (int count = 0; count < (5); count++) {
String mammalcheck = animals.get(counter).get(count);
if (mammalcheck==("Mammal")){
Mammals.add(animals.get(counter).get(count-3));//if they're a mammal, add their name to arraylist "Mammals"
}
}
}
//Print the arraylist of mammals
System.out.println("Generate an arraylist of all animals of a particular type:");
System.out.println("Mammals:");
System.out.println(Mammals);
System.out.println();
//Create an arraylist to fill with required food
ArrayList<String> foodarray = new ArrayList<String>();
for (int counter = 0; counter < animals.size(); counter++) {
for (int count = 0; count < (5); count++) {
if ((count==0)||(count==2)){//Add the names and required food of each animal.
foodarray.add(animals.get(counter).get(count));
}
}
}
//Print the arraylist of required food
System.out.println("Every animal in our zoo, and the food they require:");
System.out.println(foodarray);
System.out.println();
//Output all animals from a specific environment
System.out.println("Animals from the Jungle:");
for (int counter = 0; counter < animals.size(); counter++) {
for (int count = 0; count < (5); count++) {
if ((animals.get(counter).get(count))==("Jungle")){//If the animal is from the Jungle
System.out.println(animals.get(counter).get(0) +" the "+ animals.get(counter).get(1));//Print their name and their species
}
}
}
}
}
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