Commit 51f9c672 authored by reece.french's avatar reece.french

Attempt at ZooProject failed code

parent 61c38882
import java.util.ArrayList;
public class Animal {
static String name;
static String diet;
static String food;
static String habitat;
static String type;
public Animal(String name, String type, String diet, String food, String habitat) {
Animal.name = name;
Animal.type = type;
Animal.diet = diet;
Animal.food = food;
Animal.habitat = habitat;
}
public String display() {
return "Name: " + name + "\n" + "Type: " + type + "\n" + "Diet: " + diet + "\n"
+ "Food: " + food + "\n" + "Habitat: " + habitat;
}
public String group1() {
ArrayList<String> mammals = new ArrayList<String>();
ArrayList<String> birds = new ArrayList<String>();
ArrayList<String> fish = new ArrayList<String>();
ArrayList<String> reptiles = new ArrayList<String>();
if (type.contains("Mammal")) {
mammals.add(name);
System.out.println("Mammals list: " + mammals);
} else {
System.out.println();
}
if (type.contains("Bird")) {
birds.add(name);
System.out.println("Birds list: " + birds);
} else {
System.out.println();
}
if (type.contains("Fish")) {
fish.add(name);
System.out.println("Fish list: " + fish);
} else {
System.out.println();
}
if (type.contains("Reptile")) {
reptiles.add(name);
System.out.println("Reptile list: " + reptiles);
} else {
System.out.println();
}
return "";
}
public String group2() {
ArrayList<String> carnivores = new ArrayList<String>();
ArrayList<String> herbivores = new ArrayList<String>();
ArrayList<String> omnivores = new ArrayList<String>();
if (diet.contains("Carnivore")) {
carnivores.add(name);
System.out.println("Carnivore list: " + carnivores);
} else {
System.out.println();
}
if (diet.contains("Herbivore")) {
herbivores.add(name);
System.out.println("Herbivore list: " + herbivores);
} else {
System.out.println();
}
if (diet.contains("Omnivore")) {
omnivores.add(name);
System.out.println("Omnivore list: " + omnivores);
} else {
System.out.println();
}
return "";
}
public String group3() {
ArrayList<String> jungle = new ArrayList<String>();
ArrayList<String> desert = new ArrayList<String>();
ArrayList<String> arctic = new ArrayList<String>();
if (habitat.contains("Jungle")) {
jungle.add(name);
System.out.println("Animals in jungle habitat: " + jungle);
} else {
System.out.println();
}
if (habitat.contains("Arctic")) {
arctic.add(name);
System.out.println("Animals in arctic habitat: " + arctic);
} else {
System.out.println();
}
if (habitat.contains("Desert")) {
desert.add(name);
System.out.println("Animals in desert habitat: " + desert);
} else {
System.out.println();
}
return "";
}
public static void main(String[] args) {
Animal Animal1 = new Animal("Tiger", "Mammal", "Carnivore", "Meat", "Jungle");
Animal Animal2 = new Animal("Bear", "Mammal", "Omnivore", "Meat/plants", "Forest");
Animal Animal3 = new Animal("Shark","Fish", "Carnivore", "Meat", "Aquatic");
Animal Animal4 = new Animal("Iguana", "Reptile", "Herbivore", "Plants", "Forest");
Animal Animal5 = new Animal("Cheetah", "Mammal", "Carnivore", "Meat", "Desert");
System.out.println(Animal1.group1());
System.out.println(Animal2.group1());
System.out.println(Animal3.group1());
System.out.println(Animal4.group1());
System.out.println(Animal5.group1());
}
}
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