Commit bd353842 authored by gavin.white's avatar gavin.white

Upload New File

parent 86e2df8a
package zoo;
import java.util.ArrayList;
public class Zoo {
public static void main(String[] args) {
// Create an array list of animals, their environments, and their types
ArrayList<String> animals = new ArrayList<>();
animals.add("Tiger,Forest,Mammal");
animals.add("Lion,Savanna,Mammal");
animals.add("Zebra,Grassland,Mammal");
animals.add("Giraffe,Savanna,Mammal");
animals.add("Elephant,Grassland,Mammal");
animals.add("Kangaroo,Grassland,Mammal");
animals.add("Gorilla,Forest,Mammal");
animals.add("Penguin,Ocean,Bird");
animals.add("Owl,Forest,Bird");
animals.add("Eagle,Mountains,Bird");
animals.add("Salmon,Ocean,Fish");
animals.add("Trout,River,Fish");
animals.add("Shark,Ocean,Fish");
// Display the food, environment, and type for each animal
for (String animal : animals) {
String[] parts = animal.split(",");
String name = parts[0];
String environment = parts[1];
String type = parts[2];
System.out.print(name + ": ");
switch (type) {
case "Mammal":
switch (name) {
case "Tiger":
case "Lion":
case "Kangaroo":
case "Gorilla":
System.out.print("Meat, ");
break;
case "Zebra":
case "Giraffe":
case "Elephant":
System.out.print("Plants, ");
break;
default:
System.out.print("Unknown, ");
break;
}
break;
case "Bird":
switch (name) {
case "Penguin":
case "Owl":
case "Eagle":
System.out.print("Animals, ");
break;
default:
System.out.print("Unknown, ");
break;
}
break;
case "Fish":
switch (name) {
case "Salmon":
case "Trout":
case "Shark":
System.out.print("Fish, ");
break;
default:
System.out.print("Unknown, ");
break;
}
break;
default:
System.out.print("Unknown, ");
break;
}
System.out.print(environment + ", ");
System.out.println(type);
}
}
}
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