Commit 7b8d39ce authored by Jake's avatar Jake

First Commit

parents
public class Animals {
//declaring variables for animal objects
String animalName;
String animalFood;
String animalType;
String animalEnvironment;
String animalDescription;
//creating a constructor - allows us to write much tidier and easier to follow code
Animals(String animalName, String animalType, String animalFood, String animalEnvironment, String animalDescription) {
this.animalName = animalName;
this.animalType = animalType;
this.animalFood = animalFood;
this.animalEnvironment = animalEnvironment;
this.animalDescription = animalDescription;
}
@Override
public String toString() {
return "Animal Name: " + animalName + ", Diet: " + animalFood + ", Animal Type: " + animalType + ", Habitat: " + animalEnvironment + ", Description: " + animalDescription + "\n";
}
}
public class Bird extends Animals {
//creating a constructor - allows us to write much tidier and easier to follow code
Bird(String animalName, String animalType, String animalFood, String animalEnvironment, String animalDescription){
super(animalName, animalType, animalFood, animalEnvironment, animalDescription);
}
}
public class Fish extends Animals {
//creating a constructor - allows us to write much tidier and easier to follow code
Fish(String animalName, String animalType, String animalFood, String animalEnvironment, String animalDescription){
super(animalName, animalType, animalFood, animalEnvironment, animalDescription);
}
}
public class Mammal extends Animals {
//creating a constructor - allows us to write much tidier and easier to follow code
Mammal(String animalName, String animalType, String animalFood, String animalEnvironment, String animalDescription){
super(animalName, animalType, animalFood, animalEnvironment, animalDescription);
}
}
public class Reptile extends Animals {
//creating a constructor - allows us to write much tidier and easier to follow code
Reptile(String animalName, String animalType, String animalFood, String animalEnvironment, String animalDescription){
super(animalName, animalType, animalFood, animalEnvironment, animalDescription);
}
}
import java.util.*;
import java.util.stream.Collectors;
public class Zoo {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
ArrayList<Animals> animalList = new ArrayList<Animals>();
//creating Mammal objects
Mammal Lion = new Mammal("Lion", "Mammal", "Carnivore", "Grassland", "Strong compact body with sharp teeth and a long tail");
Mammal Boar = new Mammal("Boar", "Mammal","Omnivore", "Forest", "Large head with thick brown furred body");
Mammal Deer = new Mammal("Deer", "Mammal", "Herbivore", "Forest", "Light-brown furred with a small black nose - male deers have large antlers on their head aswell");
//adding mammal objects to single array
animalList.add(Lion);
animalList.add(Boar);
animalList.add(Deer);
//creating Bird objects
Bird Flamingo = new Bird("Flamingo", "Bird", "Omnivore", "Aquatic", "Large pink birds with long necks and sticklike legs");
Bird Penguin = new Bird("Penguin", "Bird","Carnivore", "Aquatic", "Penguins have large heads and a short neck as well as an elongated body");
Bird Ostrich = new Bird("Ostrich", "Bird", "Herbivore", "Grassland", "Large flightless bords which have a long neck protuding from heir round body");
//adding Bird objects to single array
animalList.add(Flamingo);
animalList.add(Penguin);
animalList.add(Ostrich);
//creating Fish objects
Fish Clownfish = new Fish("Clownfish", "Fish", "Omnivore", "Aquatic", "Very bright orange and white striped small fish");
Fish Parrotfish = new Fish("Parrotfish", "Fish", "Herbivore","Aquatic", "Blunt headed with a brightly colourful body");
Fish Octopus = new Fish("Octopus", "Fish", "Carnivore", "Aquatic", "Octopus have bulbous heads with eight legs");
//adding Fish objects to single array
animalList.add(Clownfish);
animalList.add(Parrotfish);
animalList.add(Octopus);
//creating Reptile objects
Reptile Crocodile = new Reptile("Crocodile", "Reptile", "Carnivore", "Aquatic", "Long bodied with many sharp teeth and a powerful jaw");
Reptile Turtle = new Reptile("Turtle", "Reptile","Omnivore", "Aquatic", "Large shell which covers their body along with four fins");
Reptile Snake = new Reptile("Snake", "Reptile", "Carnivore", "Desert", "A long thin body with no legs");
//adding Reptile objects to single array
animalList.add(Crocodile);
animalList.add(Turtle);
animalList.add(Snake);
System.out.println("Welcome to the York St John Zoo!");
while (true) {
System.out.println("Please choose from one of the following options.");
System.out.println("************************************************");
System.out.println("1. Display all details of a single animal.\n2. Display the details for a list of animals in the zoo.\n3. Generate a list of animals of a specific type.\n4. Display the food required for a list of animals.\n5. Display a list of all animals that come from a specific environment.\n");
int userDecision = input.nextInt();
if (userDecision == 1) {
singleAnimalDetails(animalList);
}
if (userDecision == 2) {
groupAnimalDetails(animalList);
}
if (userDecision == 3) {
animalTypeGeneration(animalList);
}
if (userDecision == 4) {
foodRequirementGeneration(animalList);
}
if (userDecision == 5) {
animalEnvironemtGeneration(animalList);
}
}
}
public static void singleAnimalDetails(ArrayList<Animals> animalList) {
System.out.println("You have chosen to display all the details of a single animal. Great Choice!");
System.out.println("We have a range of animals in the zoo currently! What type of animal would you like to view?");
System.out.println("1. Mammal\n2. Bird\n3. Fish\n4. Reptile\n");
//allows the user to input a number depending on which animal type they would like to view
int animalTypeChoice = input.nextInt();
//checks which animal type the user has chosen - mammal
if (animalTypeChoice == 1) {
System.out.println("You have chosen to choose an animal from the mammal category! This is our current selection.");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a mammal
if ((animalList.get(i).animalType) == "Mammal"){
//prints out all mammals in the array list
System.out.println("• " + animalList.get(i).animalName);
}
}
//asking the user which animal they would like to see the full details of
System.out.println("Please enter which animal you would like to view: ");
String nameInput = input.next();
//iterating through the animal array list
for (Animals search : animalList) {
String searchAnimalName = search.animalName;
//seeing whether the user input matches an animal in the zoo
if (nameInput.equals(searchAnimalName)) {
System.out.println("Animal Name: "+ search.animalName + ", Animal Type: " + search.animalType + ", Diet Type: " + search.animalFood + ", Environment Type: " + search.animalEnvironment + ", Animal Description: " + search.animalDescription);
}
}
}
//checks which animal type the user has chosen - Bird
if (animalTypeChoice == 2) {
System.out.println("You have chosen to choose an animal from the bird category! This is our current selection.");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a bird
if ((animalList.get(i).animalType) == "Bird"){
//prints out all mammals in the array list
System.out.println("• " + animalList.get(i).animalName);
}
}
//asking the user which animal they would like to see the full details of
System.out.println("Please enter which animal you would like to view: ");
String nameInput = input.next();
//iterating through the animal array list
for (Animals search : animalList) {
String searchAnimalName = search.animalName;
//seeing whether the user input matches an animal in the zoo
if (nameInput.equals(searchAnimalName)) {
System.out.println("Animal Name: "+ search.animalName + ", Animal Type: " + search.animalType + ", Diet Type: " + search.animalFood + ", Environment Type: " + search.animalEnvironment + ", Animal Description: " + search.animalDescription);
}
}
}
//checks which animal type the user has chosen - Fish
if (animalTypeChoice == 3) {
System.out.println("You have chosen to choose an animal from the fish category! This is our current selection.");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a fish
if ((animalList.get(i).animalType) == "Fish"){
//prints out all fish in the array list
System.out.println("• " + animalList.get(i).animalName);
}
}
//asking the user which animal they would like to see the full details of
System.out.println("Please enter which animal you would like to view: ");
String nameInput = input.next();
//iterating through the animal array list
for (Animals search : animalList) {
String searchAnimalName = search.animalName;
//seeing whether the user input matches an animal in the zoo
if (nameInput.equals(searchAnimalName)) {
System.out.println("Animal Name: "+ search.animalName + ", Animal Type: " + search.animalType + ", Diet Type: " + search.animalFood + ", Environment Type: " + search.animalEnvironment + ", Animal Description: " + search.animalDescription);
}
}
}
//checks which animal type the user has chosen - Reptile
if (animalTypeChoice == 4) {
System.out.println("You have chosen to choose an animal from the reptile category! This is our current selection.");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a reptile
if ((animalList.get(i).animalType) == "Reptile"){
//prints out all reptiles in the array list
System.out.println("• " + animalList.get(i).animalName);
}
}
//asking the user which animal they would like to see the full details of
System.out.println("Please enter which animal you would like to view: ");
String nameInput = input.next();
//iterating through the animal array list
for (Animals search : animalList) {
String searchAnimalName = search.animalName;
//seeing whether the user input matches an animal in the zoo
if (nameInput.equals(searchAnimalName)) {
System.out.println("Animal Name: "+ search.animalName + ", Animal Type: " + search.animalType + ", Diet Type: " + search.animalFood + ", Environment Type: " + search.animalEnvironment + ", Animal Description: " + search.animalDescription);
}
}
}
//checks to see whether the user's input is a valid option and if not returns them to the menu
if (animalTypeChoice < 1 | animalTypeChoice > 4) {
System.out.println("You have chosen an invalid option! Please re-try again.");
}
}
public static void groupAnimalDetails(ArrayList<Animals> animalList) {
System.out.println("You have chosen to display the details of a group of animals. Great Choice!");
System.out.println("What animal group would you like to learn about?");
System.out.println("1. Mammal\n2. Bird\n3. Fish\n4. Reptile\n");
int animalTypeChoice = input.nextInt();
if (animalTypeChoice == 1) {
System.out.println("You have chosen to view the details of all of the mammal type animals we have at the zoo currently!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a mammal
if ((animalList.get(i).animalType) == "Mammal"){
//prints out all mammals in the array list
System.out.println("Animal Name: "+ animalList.get(i).animalName + ", Animal Type: " + animalList.get(i).animalType + ", Diet Type: " + animalList.get(i).animalFood + ", Environment Type: " + animalList.get(i).animalEnvironment + ", Animal Description: " + animalList.get(i).animalDescription);
}
}
}
if (animalTypeChoice == 2) {
System.out.println("You have chosen to view the details of all of the bird type animals we have at the zoo currently!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a bird
if ((animalList.get(i).animalType) == "Bird"){
//prints out all bird in the array list
System.out.println("Animal Name: "+ animalList.get(i).animalName + ", Animal Type: " + animalList.get(i).animalType + ", Diet Type: " + animalList.get(i).animalFood + ", Environment Type: " + animalList.get(i).animalEnvironment + ", Animal Description: " + animalList.get(i).animalDescription);
}
}
}
if (animalTypeChoice == 3) {
System.out.println("You have chosen to view the details of all of the fish type animals we have at the zoo currently!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a fish
if ((animalList.get(i).animalType) == "Fish"){
//prints out all fish in the array list
System.out.println("Animal Name: "+ animalList.get(i).animalName + ", Animal Type: " + animalList.get(i).animalType + ", Diet Type: " + animalList.get(i).animalFood + ", Environment Type: " + animalList.get(i).animalEnvironment + ", Animal Description: " + animalList.get(i).animalDescription);
}
}
}
if (animalTypeChoice == 4) {
System.out.println("You have chosen to view the details of all of the reptile type animals we have at the zoo currently!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a reptile
if ((animalList.get(i).animalType) == "Reptile"){
//prints out all reptiles in the array list
System.out.println("Animal Name: "+ animalList.get(i).animalName + ", Animal Type: " + animalList.get(i).animalType + ", Diet Type: " + animalList.get(i).animalFood + ", Environment Type: " + animalList.get(i).animalEnvironment + ", Animal Description: " + animalList.get(i).animalDescription);
}
}
}
}
public static void animalTypeGeneration(ArrayList<Animals> animalList) {
System.out.println("You have chosen to generate a list of animals from a specific type. Great Choice!");
System.out.println("Which type of animals woudld you like to view?");
System.out.println("1. Mammal\n2. Bird\n3. Fish\n4. Reptile\n");
//allows the user to input a number depending on which animal type they would like to view
int animalTypeChoice = input.nextInt();
if (animalTypeChoice == 1) {
System.out.println("You have chosen to view all of the animals from the mammal group type!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a mammal
if ((animalList.get(i).animalType) == "Mammal"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (animalTypeChoice == 2) {
System.out.println("You have chosen to view all of the animals from the bird group type!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a bird
if ((animalList.get(i).animalType) == "Bird"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (animalTypeChoice == 3) {
System.out.println("You have chosen to view all of the animals from the fish group type!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a fish
if ((animalList.get(i).animalType) == "Fish"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (animalTypeChoice == 4) {
System.out.println("You have chosen to view all of the animals from the reptile group type!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a reptile
if ((animalList.get(i).animalType) == "Reptile"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
}
public static void foodRequirementGeneration(ArrayList<Animals> animalList) {
System.out.println("You have chosen to display the food required for a list of animals!");
System.out.println("Which food type would you like to view?");
System.out.println("1. Carnivore (meat only)\n2. Herbivore (vegetation only)\n3. Omnivore(meat and vegetation)\n");
//allows the user to input a number depending on which animal diet type they would like to view
int animalDietChoice = input.nextInt();
if (animalDietChoice == 1) {
System.out.println("You have chosen to view all of the animals at the zoo which are carnivorous!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is carnivorous
if ((animalList.get(i).animalFood) == "Carnivore"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (animalDietChoice == 2) {
System.out.println("You have chosen to view all of the animals at the zoo which are herbivorous!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a herbivorous
if ((animalList.get(i).animalFood) == "Herbivore"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (animalDietChoice == 3) {
System.out.println("You have chosen to view all of the animals at the zoo which are omnivorous!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is a omnivorous
if ((animalList.get(i).animalFood) == "Omnivore"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
}
public static void animalEnvironemtGeneration(ArrayList<Animals> animalList) {
System.out.println("You have chosen to display all animals which come from a specific environment!");
System.out.println("Which animal environment would you like to view?");
System.out.println("1. Aquatic\n2. Desert\n3. Forest\n4. Grassland\n5. Tundra\n");
//allows the user to input a number depending on which animal type they would like to view
int biomeChoice = input.nextInt();
if (biomeChoice == 1) {
System.out.println("You have chosen to view all of the animals from the aquatic biome!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is aquatic
if ((animalList.get(i).animalEnvironment) == "Aquatic"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (biomeChoice == 2) {
System.out.println("You have chosen to view all of the animals from the desert biome!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is from the desert
if ((animalList.get(i).animalEnvironment) == "Desert"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (biomeChoice == 3) {
System.out.println("You have chosen to view all of the animals from the forest biome!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is from the forest
if ((animalList.get(i).animalEnvironment) == "Forest"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (biomeChoice == 4) {
System.out.println("You have chosen to view all of the animals from the grassland biome!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is from grassland
if ((animalList.get(i).animalEnvironment) == "Grassland"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
if (biomeChoice == 5) {
System.out.println("You have chosen to view all of the animals from the Tundra biome!");
//for loop to iterate through the array list of animals
for (int i = 0; i < animalList.size(); i++) {
//checks to see whether each animal is from the tundra
if ((animalList.get(i).animalEnvironment) == "Tundra"){
System.out.println("• "+ animalList.get(i).animalName);
}
}
}
}
}
\ No newline at end of file
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