Commit 9eed3f69 authored by qhaig's avatar qhaig

final commit

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-13">
<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>zoo</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=13
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=13
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=13
module zoo {
}
\ No newline at end of file
package zoo;
public class Animal
{
public String food;
public String habitat;
public String name;
}
package zoo;
public class Birds extends Animal {
public String type = "Birds";
public boolean flies;
public boolean fightless;
}
package zoo;
public class Fish extends Animal {
public String type = "Fish";
public boolean ocean;
public boolean river;
public boolean lake;
}
package zoo;
public class Mammal extends Animal {
public String type = "Mammal";
public int numbeOfLegs;
}
package zoo;
public class Reptile extends Animal{
public String type = "Reptile";
public int numbeOfLegs;
}
package zoo;
import java.util.ArrayList;
import java.util.Scanner;
public class YsjcsZoo {
//Create scanner
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
//create ArrayLists
ArrayList<Mammal> mammals = new ArrayList<Mammal>();
ArrayList<Animal> animals = new ArrayList<Animal>();
Mammal Monkey = new Mammal();
Monkey.name = "Monkey";
Monkey.numbeOfLegs = 2;
Monkey.food = "Fruit";
Monkey.habitat = "Forest";
Mammal Cheetah = new Mammal();
Cheetah.name = "Cheetah";
Cheetah.numbeOfLegs = 4;
Cheetah.food = "Meat";
Cheetah.habitat = "Savannah";
Mammal Zebra = new Mammal();
Zebra.name = "Zebra";
Zebra.numbeOfLegs = 4;
Zebra.habitat = "Savannah";
Zebra.food = "Plants";
Mammal polarBear = new Mammal();
polarBear.name = "Polar Bear";
polarBear.food ="Fish";
polarBear.habitat ="Artic";
polarBear.numbeOfLegs = 4;
Mammal narwhal = new Mammal();
narwhal.name = "Narwhal";
narwhal.habitat = "Ocean";
narwhal.food ="Fish";
narwhal.numbeOfLegs = 0;
mammals.add(Monkey);
animals.add(Monkey);
mammals.add(Cheetah);
animals.add(Cheetah);
mammals.add(Zebra);
animals.add(Zebra);
mammals.add(polarBear);
animals.add(polarBear);
mammals.add(narwhal);
animals.add(narwhal);
ArrayList<Reptile> reptiles = new ArrayList<Reptile>();
Reptile crocodile = new Reptile();
crocodile.name = "Crocodile";
crocodile.habitat = "River";
crocodile.food = "Meat";
crocodile.numbeOfLegs = 4;
Reptile komodo = new Reptile();
komodo.name = "Komodo Dragon";
komodo.habitat = "River";
komodo.food = "Meat";
komodo.numbeOfLegs = 4;
Reptile turtle = new Reptile();
turtle.name = "Alligator Snapping Turtle";
turtle.habitat = "Lake";
turtle.food = "Reptiles";
turtle.numbeOfLegs = 4;
Reptile boa = new Reptile();
boa.name = "Brazillian Rainbow Boa";
boa.food = "Meat";
boa.habitat = "Forest";
boa.numbeOfLegs = 0;
Reptile chuckwalla = new Reptile();
chuckwalla.name = "Western Chuckwalla";
chuckwalla.habitat = "Desert";
chuckwalla.food = "Plants";
chuckwalla.numbeOfLegs = 4;
reptiles.add(chuckwalla);
animals.add(chuckwalla);
reptiles.add(crocodile);
animals.add(crocodile);
reptiles.add(turtle);
animals.add(turtle);
reptiles.add(boa);
animals.add(boa);
reptiles.add(komodo);
animals.add(komodo);
ArrayList<Birds> birds = new ArrayList<Birds>();
Birds eagle = new Birds();
eagle.name = "Crowned Eagle";
eagle.flies = true;
eagle.food = "Fish";
eagle.habitat = "Meat";
Birds bald = new Birds();
bald.name = "Bald Eagle";
bald.flies = true;
bald.food = "Fish";
bald.habitat = "Lake";
Birds kookaburra = new Birds();
kookaburra.name = "Kookaburra";
kookaburra.flies = true;
kookaburra.food = "Reptiles";
kookaburra.habitat = "Forest";
Birds ostrich = new Birds();
ostrich.name = "Ostrich";
ostrich.fightless = true;
ostrich.food = "Plants";
ostrich.habitat = "Savannah";
Birds puffin = new Birds();
puffin.name = "Tufted Puffin";
puffin.flies = true;
puffin.food = "Fish";
puffin.habitat = "Ocean";
birds.add(puffin);
animals.add(puffin);
birds.add(eagle);
animals.add(eagle);
birds.add(bald);
animals.add(bald);
birds.add(kookaburra);
animals.add(kookaburra);
birds.add(ostrich);
animals.add(ostrich);
ArrayList<Fish> fish = new ArrayList<Fish>();
Fish ray = new Fish();
ray.name = "Motoro Ray";
ray.food = "Fish";
ray.habitat = "River";
ray.river = true;
Fish piranha = new Fish();
piranha.name= "Piranha";
piranha.habitat = "River";
piranha.food = "Meat";
piranha.river = true;
Fish cichild = new Fish();
cichild.name = "Jaguar Cichild";
cichild.food = "Fish";
cichild.habitat = "Lake";
cichild.lake = true;
Fish catfish = new Fish();
catfish.name = "Freshwater Catfish";
catfish.food = "Plants";
catfish.habitat = "River";
catfish.river = true;
Fish lungfish = new Fish();
lungfish.name = "West African Lungfish";
lungfish.food = "Reptiles";
lungfish.habitat = "River";
lungfish.river = true;
fish.add(lungfish);
animals.add(lungfish);
fish.add(catfish);
animals.add(catfish);
fish.add(cichild);
animals.add(cichild);
fish.add(piranha);
animals.add(piranha);
fish.add(ray);
animals.add(ray);
//create menu to choose what to search
while(true) {
System.out.println(
"------- Menu --------\n" +
"1 - Print all animals\n" +
"2 - Search specific animal\n" +
"3 - Search specific habitat\n" +
"4 - Search specific food\n" +
"5 - Quit\n" +
"Please enter choice > ");
int choice =input.nextInt();
//switch case to equate each method to the correct menu option
switch(choice) {
case 1:
printDetailsAnimals(animals);
break;
case 2:
System.out.println("Enter query");
String query = input.next();
searchAnimals(animals, query);
System.out.print(query);
break;
case 3:
System.out.println("Enter query");
String habitatQuery = input.next();
searchHabitat(animals, habitatQuery);
break;
case 4:
System.out.println("Enter query");
String foodQuery = input.next();
searchFood(animals, foodQuery);
break;
case 5: return;
default:
System.out.println("Invalid choice, valid choices are 1 to 5.");
}
}
}
//prints animal array
public static void printDetailsAnimals(ArrayList<Animal> animals) {
for(Animal animal : animals)
{
System.out.println(animal.name);
System.out.println(animal.habitat);
System.out.println(animal.food);
}
}
//search animal array
public static void searchAnimals(ArrayList<Animal> animals, String query) {
for(Animal animal : animals)
{
if(animal.name.contentEquals(query)) {
System.out.println(animal.name);
System.out.println(animal.habitat);
System.out.println(animal.food);
}
}
}
//search animal array for the habitat
public static void searchHabitat(ArrayList<Animal> animals, String habitatQuery) {
for(Animal animal : animals)
{
if(animal.habitat.contentEquals(habitatQuery)) {
System.out.println(animal.name);
System.out.println(animal.food);
}
}
}
//search animal array for food type
public static void searchFood(ArrayList<Animal> animals, String foodQuery)
{
for(Animal animal : animals)
{
if(animal.food.contentEquals(foodQuery)) {
System.out.println(animal.name);
System.out.println(animal.habitat);
}
}
}
}
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