Commit 318c409c authored by Eky's avatar Eky

new update

parent 5410072d
package zooApplication; package zooApplication;
import java.util.ArrayList;
import java.util.Scanner;
public class Main public class Main
{ {
@SuppressWarnings("serial")
public static ArrayList<String> batSpec = new ArrayList<String>() {{add("Can Fly");}};
@SuppressWarnings("serial")
public static ArrayList<String> platSpec = new ArrayList<String>() {{add("Egg Laying");add("Venomous");}};
@SuppressWarnings("serial")
public static ArrayList<String> dragSpec = new ArrayList<String>()
{{
add("Can Fly");
add("Breathes Fire");
add("Large Predator");
}};
public static Animal wolf = new Mammal("Wolf","Mountain","Meat");
public static Animal tiger = new Mammal("Tiger","Jungle","Meat",true);
public static Animal fruitBat = new Mammal("Fruit Bat","Jungle","Fruit",batSpec);
public static Animal platypus = new Mammal("Platypus","Riverlands","Invertebrates",platSpec);
public static Animal eagle = new Avian("Eagle","Mountain","Meat");
public static Animal emu = new Avian("Emu","Desert","Vegetation",false);
public static Animal shark = new Piscine("Shark","Water","Meat");
public static Animal carp = new Piscine("Carp","Water","Vegetation",false);
public static Animal cobra = new Reptile("Cobra","Desert","Meat",true);
public static Animal crocodile = new Reptile("Crocodile","Riverlands","Meat") {{addTrait("Large Predator");}};
public static Animal dragon = new Mythic("Dragon","Volcano","Maidens",dragSpec);
@SuppressWarnings("serial")
public static ArrayList<Animal> zooAnimals = new ArrayList<Animal>()
{{
add(wolf);add(tiger);add(fruitBat);add(platypus);
add(eagle);add(emu);
add(shark);add(carp);
add(cobra);add(crocodile);
add(dragon);
}};
public static Zoo ysjZoo = new Zoo(zooAnimals);
public static void main(String[] args) public static void main(String[] args)
{ {
org.junit.runner.JUnitCore.main("zooApplication.UnitTest"); //org.junit.runner.JUnitCore.main("zooApplication.UnitTest");
boolean end = false;
Scanner scan = new Scanner(System.in);
String input;
String name;
System.out.println("Welcome to the Zoo!\n");
do
{
System.out.println("\nPlease choose an option:");
System.out.println("1: Search for animal and display details.");
System.out.println("2: Display all animals in zoo.");
System.out.println("3: Display list of animals of specific type.");
System.out.println("4: Display food required for list of animals of certain type.");
System.out.println("5: Display all animals from a certain environment.");
System.out.println("x: Exit.");
input = scan.next();
if(input.equals("1"))
{
System.out.println("\n\nPlease enter name of animal (capital letter for name):");
name = scan.next();
ysjZoo.displayDetails(name);
}
else if(input.equals("2"))
{
ysjZoo.displayAll(ysjZoo.zooList);
}
else if(input.equals("3"))
{
System.out.println("\n\nPlease enter name of type (capital letter for name):");
name = scan.next();
ArrayList<Animal> types = ysjZoo.typeList(name);
ysjZoo.displayAll(types);
}
else if(input.equals("4"))
{
System.out.println("\n\nPlease enter name of type (capital letter for name):");
name = scan.next();
ArrayList<Animal> types = ysjZoo.typeList(name);
System.out.println(ysjZoo.foodList(types));
}
else if(input.equals("5"))
{
System.out.println("\n\nPlease enter name of environment (capital letter for name):");
name = scan.next();
ArrayList<Animal> enviros = ysjZoo.enviroList(zooAnimals, name);
ysjZoo.displayAll(enviros);
}
else if(input.equals("x"))
{
end = true;
}
}while(end==false);
} }
} }
...@@ -50,9 +50,9 @@ public class UnitTest ...@@ -50,9 +50,9 @@ public class UnitTest
@Test @Test
public void testBasic() public void testBasic()
{ {
assertEquals(true,ysjZoo.containsAnimal(wolf)); assertEquals(true,ysjZoo.containsAnimal("wolf"));
System.out.println("\nTest: Display Single Animal\n"); System.out.println("\nTest: Display Single Animal\n");
ysjZoo.displayDetails(wolf); ysjZoo.displayDetails("wolf");
} }
@Test @Test
......
...@@ -28,26 +28,43 @@ public class Zoo ...@@ -28,26 +28,43 @@ public class Zoo
} }
//Returns true if list contains animal //Returns true if list contains animal
public boolean containsAnimal(Animal animal) public boolean containsAnimal(String animal)
{ {
if(zooList.contains(animal)) for(int i=0;i<zooList.size();i++)
{ {
return true; if(zooList.get(i).species.equals(animal))
{
return true;
}
} }
return false; return false;
} }
//Display details of specific animal in list public int animalIndex(String animal)
public void displayDetails(Animal animal)
{ {
if(containsAnimal(animal)) for(int i=0;i<zooList.size();i++)
{
if(zooList.get(i).species.equals(animal))
{
return i;
}
}
return 0;
}
//Display details of specific animal in list
public void displayDetails(String input)
{
if(containsAnimal(input))
{ {
Animal animal = zooList.get(animalIndex(input));
System.out.println("Name: "+animal.species+"\nHabitat: "+animal.habitat+"\nFood: "+animal.food); System.out.println("Name: "+animal.species+"\nHabitat: "+animal.habitat+"\nFood: "+animal.food);
if(animal.specialTraits.size()>0) if(animal.specialTraits.size()>0)
{ {
System.out.println("Special Traits: "+animal.specialTraits); System.out.println("Special Traits: "+animal.specialTraits);
} }
} }
else {System.out.println("This animal is not in the zoo!");}
} }
//Displays all animals in list //Displays all animals in list
...@@ -55,7 +72,7 @@ public class Zoo ...@@ -55,7 +72,7 @@ public class Zoo
{ {
for(int i=0;i<input.size();i++) for(int i=0;i<input.size();i++)
{ {
displayDetails(input.get(i)); displayDetails(input.get(i).species);
System.out.println(""); System.out.println("");
} }
} }
......
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