Commit ea6edf31 authored by Jacob's avatar Jacob

.

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Real Zoo Assignment</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
public class allAnimals {
String name;
String type;
String food;
String enviroment;
String description;
allAnimals (String name, String type, String food, String enviroment, String description) {
this.name = name;
this.type = type;
this.food = food;
this.enviroment = enviroment;
this.description = description;
}
@Override
public String toString() {
return "Name: " + name + "| Diet: " + food + "| Type: " + type + "| Habitat: "
+ enviroment + "| Description: " + description + "|\n";
}
}
public class birds extends allAnimals {
birds (String name, String type, String food, String enviroment, String description){
super(name, type, food, enviroment, description);
}
}
public class fish extends allAnimals {
fish (String name, String type, String food, String enviroment, String description){
super(name, type, food, enviroment, description);
}
}
public class mammals extends allAnimals {
mammals (String name, String type, String food, String enviroment, String description){
super(name, type, food, enviroment, description);
}
}
public class reptiles extends allAnimals{
reptiles (String name, String type, String food, String enviroment, String description){
super(name, type, food, enviroment, description);
}
}
import java.util.*;
public class zooMain {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean running = true;
ArrayList<allAnimals> animalList = new ArrayList<allAnimals>();
animalList.add(new mammals("Lion", "Mammal", "Carnivore", "Grasslands", "Big cat"));
animalList.add(new mammals("Elephant", "Mammal", "Herbivore", "Savannas", "Large with four lefs and a long trunk"));
animalList.add(new mammals("Gorilla", "Mammal", "Omnivore", "Jungles", "Huamnoid form, highly inteligent"));
animalList.add(new mammals("Giraffe", "Mammal", "Herbivore", "Savannas", "Very long neck, four legs"));
animalList.add(new birds("Penguin", "Bird", "Carnivore", "Sea", "Black and white bird"));
animalList.add(new birds("Owl", "Bird", "Carnivore", "Forests", "Can rotate head 360 degrees"));
animalList.add(new birds("Ostrich", "Bird", "Herbivores", "Savannas", "Long neck, very fast, lays huge eggs"));
animalList.add(new birds("Eagle", "Bird", "Carnivore", "Forests", "Bird of prey"));
animalList.add(new fish("Swordfish", "Fish", "Carnivore", "Sea", "Long flat pointed bill"));
animalList.add(new fish("Whale shark", "Fish", "Carnivore", "Sea", "Can grow to be as big as a bus"));
animalList.add(new fish("Goldfish", "Fish", "Omnivore", "Sea", "Golden in colour"));
animalList.add(new fish("Zebrafish", "Fish", "Omnivore", "Sea", "Striped pattern"));
animalList.add(new reptiles("Bearded Dragon", "Reptile", "Omnivores", "Savanna", "Four legs, long tail"));
animalList.add(new reptiles("Gecko", "Reptile", "Omnivore", "Deserts", "Tail can fall off when scared"));
animalList.add(new reptiles("Aligator", "Reptile", "Carnivore", "Fresh water", "Lots of sharp teeth and a powerful jaw"));
animalList.add(new reptiles("Tortoise", "Reptile", "Herbivore", "Deserts", "Hard shell on back"));
while (running == true) {
System.out.println("Welcome to York St John Zoo.\n"
+ "Press (1) to see a list of all animals with details. \n"
+ "Press (2) to display details of a single animal. \n"
+ "Press (3) to search for animals via type. \n"
+ "Press (4) to search for animals via diet. \n"
+ "And press (5) to search for animals via Habitat");
int tempAns = sc.nextInt();
if (tempAns == 1) {
System.out.println(animalList);
}
if (tempAns == 2) {
singleAnimal(animalList, sc);
}
if (tempAns == 4) {
dietAnimal(animalList, sc);
}
if (tempAns == 3) {
typeAnimal(animalList, sc);
}
if (tempAns == 5) {
habitatAnimal(animalList, sc);
}
else {
System.out.println("That was not a valid option!");
}
}
}
public static void singleAnimal(ArrayList<allAnimals> animalList, Scanner sc) {
System.out.println("What animal would you like to view (Case sensitive)");
String tempName = sc.next();
for (allAnimals tempAnimal : animalList) {
if (tempAnimal.name.equals(tempName)) {
System.out.println("\n\nName: " + tempAnimal.name + "\n"
+ "Type: " + tempAnimal.type + "\n"
+ "Diet: " + tempAnimal.food + "\n"
+ "Habitat: " + tempAnimal.enviroment + "\n"
+ "Description: " + tempAnimal.description + "\n");
}
else {
System.out.println("That was not a valid option!");
}
}
}
public static void typeAnimal(ArrayList<allAnimals> animalList, Scanner sc) {
System.out.println("What type of animal would you like to view? (Case sensitive) \n"
+ "Mammal \n"
+ "Bird \n"
+ "Fish \n"
+ "Reptile \n\n");
String tempType = sc.next();
for (allAnimals tempAnimal : animalList) {
if (tempAnimal.type.equals(tempType)) {
System.out.println("\n\nName: " + tempAnimal.name + "\n"
+ "Type: " + tempAnimal.type + "\n"
+ "Diet: " + tempAnimal.food + "\n"
+ "Habitat: " + tempAnimal.enviroment + "\n"
+ "Description: " + tempAnimal.description + "\n");
}
else {
System.out.println("That was not a valid option!");
}
}
}
public static void dietAnimal(ArrayList<allAnimals> animalList, Scanner sc) {
System.out.println("What type of diet would you like to search for? (Case sensitive) \n"
+ "Carnovire\n"
+ "Herbivore\n"
+ "Omnivore\n\n");
String tempDiet = sc.next();
for (allAnimals tempAnimal : animalList) {
if (tempAnimal.food.equals(tempDiet)) {
System.out.println("\n\nName: " + tempAnimal.name + "\n"
+ "Type: " + tempAnimal.type + "\n"
+ "Diet: " + tempAnimal.food + "\n"
+ "Habitat: " + tempAnimal.enviroment + "\n"
+ "Description: " + tempAnimal.description + "\n");
}
else {
System.out.println("That was not a valid option!");
}
}
}
public static void habitatAnimal(ArrayList<allAnimals> animalList, Scanner sc) {
System.out.println("What habitat would you like to search for? (Case sensitive) \n"
+ "Grasslands \n"
+ "Savannas \n"
+ "Jungles \n"
+ "Sea \n"
+ "Forests \n"
+ "Fresh water \n"
+ "Deserts \n");
String tempHabitat = sc.next();
for (allAnimals tempAnimal : animalList) {
if (tempAnimal.enviroment.equals(tempHabitat)) {
System.out.println("\n\nName: " + tempAnimal.name + "\n"
+ "Type: " + tempAnimal.type + "\n"
+ "Diet: " + tempAnimal.food + "\n"
+ "Habitat: " + tempAnimal.enviroment + "\n"
+ "Description: " + tempAnimal.description + "\n");
}
else {
System.out.println("That was not a valid option!");
}
}
}
}
\ 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