Commit 05bcccc9 authored by Tom's avatar Tom

Final commit for the zoo

parent 580246cd
......@@ -2,40 +2,201 @@ import java.util.ArrayList;
public class animals {
String species;
String food;
String enviroment;
String type;
ArrayList<animals> animalsArray = new ArrayList<animals>();
public animals(String species, String food, String enviroment, String type) {
//Setting up arrays for the different parameters
public ArrayList<String> animalsSpecies = new ArrayList<String>();
public ArrayList<String> animalsFood = new ArrayList<String>();
public ArrayList<String> animalsEnviroment = new ArrayList<String>();
public ArrayList<String> animalsType = new ArrayList<String>();
//Creating a method which defines all of the animal species
public void animalsGetSpecies (String species) {
animalsSpecies.add(species);
//This add the item in the brackets to the array list
animalsSpecies.add("Lion");
animalsSpecies.add("Meerkat");
animalsSpecies.add("Snake");
animalsSpecies.add("Chameleons");
animalsSpecies.add("Catfish");
animalsSpecies.add("Swordfish");
animalsSpecies.add("Parrot");
animalsSpecies.add("Penguin");
}
//Creating a method which defines all of the food
public void animalsGetFood (String food) {
animalsFood.add(food);
//add items to array list
animalsFood.add("Meat");
animalsFood.add("Insects-and-Small-Amounts-of-Meat");
animalsFood.add("Mice");
animalsFood.add("Insects");
animalsFood.add("Small-Fish");
animalsFood.add("Small-Fish");
animalsFood.add("Seeds");
animalsFood.add("Fish");
}
//Creating a method which defines all of the environments
public void animalsGetEnviroment (String enviroment) {
animalsEnviroment.add(enviroment);
animalsEnviroment.add("Grasslands");
animalsEnviroment.add("Desert-Tank");
animalsEnviroment.add("Sand-Tank");
animalsEnviroment.add("Rain-Forest-Tank");
animalsEnviroment.add("Ocean-Tank");
animalsEnviroment.add("Ocean-Tank");
animalsEnviroment.add("Rain-Forest-Tank");
animalsEnviroment.add("Antartica-Tank");
}
//Creating a method which defines all of the animal types
public void animalsGetType (String type) {
animalsType.add(type);
//add to the array list
animalsType.add("Mammal");
animalsType.add("Mammal");
animalsType.add("Reptile");
animalsType.add("Reptile");
animalsType.add("Fish");
animalsType.add("Fish");
animalsType.add("Bird");
animalsType.add("Bird");
this.species = species;
this.food = food;
this.enviroment = enviroment;
this.type = type;
}
public void addAnimal(animals ann) {
animalsArray.add(ann);
// creates a method which views all of the animals and shows all of their descriptions
public void viewAllAnimals() {
// A for loop finding the size of the list and showing all the animals till it reaches the end of the array
for(int i = 0; i < animalsSpecies.size(); i++) {
System.out.println("Species: " + animalsSpecies.get(i) + ", Food: " + animalsFood.get(i) + ", Enviroment: " + animalsEnviroment.get(i)
+ ", Type: " + animalsType.get(i) );
}
}
//this method takes a user input and then goes down the array list till it finds it. This one was for a specific animal
public void specificAnimals(String userinput) {
for(int i = 0; i < animalsSpecies.size(); i++) {
if (animalsSpecies.get(i).equals(userinput))
System.out.println("Species: " + animalsSpecies.get(i) + ", Food: " + animalsFood.get(i) + ", Enviroment: " + animalsEnviroment.get(i)
+ ", Type: " + animalsType.get(i));
}
}
public void allAnimals() {
//this method takes a user input and then goes down the array list till it finds it. This one was for a specific type
public void specificType(String userinput) {
animals lion = new animals("Lion", "Meat", "Grasslands", "Mammal");
addAnimal(lion);
for (int i = 0; i < animalsType.size(); i++) {
if (animalsType.get(i).equals(userinput))
System.out.println("Species: " + animalsSpecies.get(i) + ", Food: " + animalsFood.get(i) + ", Enviroment: " + animalsEnviroment.get(i)
+ ", Type: " + animalsType.get(i));
}
}
//Shows all the animals and the food they eat
public void viewAllAnimalsFood() {
for(int i = 0; i < animalsSpecies.size(); i++) {
System.out.println("Species: " + animalsSpecies.get(i) + ", Food: " + animalsFood.get(i));
}
}
//this method takes a user input and then goes down the array list till it finds it. This one was for the environments
public void specificEnviroment(String userinput) {
for (int i = 0; i < animalsEnviroment.size(); i++) {
if (animalsEnviroment.get(i).equals(userinput))
System.out.println("Species: " + animalsSpecies.get(i) + ", Food: " + animalsFood.get(i) + ", Enviroment: " + animalsEnviroment.get(i)
+ ", Type: " + animalsType.get(i));
}
}
System.out.print(species);
}
}
......@@ -8,5 +8,8 @@ public class methods {
}
public void displayAllAnimals() {
}
}
......@@ -8,50 +8,165 @@ public class zoo{
static Scanner input = new Scanner(System.in);
//This is the start of my main
public static void main(String[] args) {
//Here I am creating some variables, I will be using these later on.
int w = 1;
String animalInput;
String typeInput;
String environmentInput;
//Starting a while loop so that the user can return to the main menu at any time
while(w == 1) {
//Here I have created some variables, I put the continueProgram variable here instead of outside the while loop. I did this because
//I want the variable to reset back to 0 every time the user returns to the main menu.
int continueProgram = 0;
int menuChoice;
methods zoo = new methods();
//Here I reference the animals class and make a new version called zoo, this allows me to use the methods and variables inside of the
//animals class
animals zoo = new animals();
//Creating references to methods so that I can have access to the data inside of them
zoo.animalsGetSpecies("Zoo Keeper Karen");
zoo.animalsGetFood("Expired Meal Deals");
zoo.animalsGetEnviroment("Outside Managers Office");
zoo.animalsGetType("Reptile");
//Creating the menu screen
System.out.print("York St John Zoo: Menu\n\nPlease select the number of the section you would like to view!\n\n1: View Individual Animal.\n2. Display"
+ " the details of each animal.\n3. View animal of particular type.\n4. Display the food required for all animals.\n5. Exit program\n");
System.out.print("\n\nYork St John Zoo: Menu\n\nPlease select the number of the section you would like to view!\n\n1: View Individual Animal.\n2. Display"
+ " the details of each animal.\n3. View animal of particular type.\n4. "
+ "Display the food required for all animals.\n5. Display list of animals from a specific environment\n6. Exit Program\n\n");
//Allows the user to choose which section they want to go to
menuChoice = input.nextInt();
//A switch statement to send the user to their desired option
switch(menuChoice) {
case 1:
case 2:
System.out.print("Please enter the species of animal you would like to view. To see what animals are available choose option 2 on the menu"
+ " screen.\nPlease note that this is case sensitive\n\n");
//Allows the user to decide what animal they want to view
animalInput = input.next();
zoo.allAnimals();
//Runs the specificAnimals method
zoo.specificAnimals(animalInput);
System.out.println("\nType 1 to go back to the menu");
//User can input the correct number to make the program continue
continueProgram =input.nextInt();
//If the input number is equal to 1 the program will continue
if(continueProgram == 1) {
break;
}
case 2:
System.out.print("Here are all of our animals");
//Runs the view all animals method
zoo.viewAllAnimals();
System.out.println("\nType 1 to go back to the menu");
//This section allows the user to enter a number and if that number matches with the number in the if statement the program will continue
continueProgram =input.nextInt();
if(continueProgram == 1) {
break;
}
case 3:
System.out.print("Please enter the type you would like to view. There are four types; Mammals, Reptiles, Fish and Birds. "
+ "\nPlease note that this is case sensitive\n\n");
//Allows the user to input animal type
typeInput = input.next();
//Runs the specificType method inside of my animals class
zoo.specificType(typeInput);
System.out.println("\nType 1 to go back to the menu");
//This section allows the user to enter a number and if that number matches with the number in the if statement the program will continue
continueProgram =input.nextInt();
if(continueProgram == 1) {
break;
}
case 4:
System.out.print("Here is the food eaten by our animals.");
//Runs the viewAllAnimalsFood method within my animals class
zoo.viewAllAnimalsFood();
System.out.println("\nType 1 to go back to the menu");
//This section allows the user to enter a number and if that number matches with the number in the if statement the program will continue
continueProgram =input.nextInt();
if(continueProgram == 1) {
break;
}
case 5:
System.out.print("Please enter the environment you would like to view. To see what animals are available choose option 2 on the menu\n"
+ " screen. Please note that this is case sensitive\n\n");
//Allows the user to enter a environment
environmentInput = input.next();
//Runs the specificEnviroment method
zoo.specificEnviroment(environmentInput);
//This section allows the user to enter a number and if that number matches with the number in the if statement the program will continue
System.out.println("\nType 1 to go back to the menu");
continueProgram =input.nextInt();
if(continueProgram == 1) {
break;
}
case 6:
//Displays text and exits program
System.out.println("\nExiting Program!");
System.exit(0);
break;
default:
//If the wrong number is input this code will run.
System.out.print("That option was not on the list! Please type 1 to continue");
continueProgram =input.nextInt();
if(continueProgram == 1) {
break;
}
}
}}
......
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