Commit 5b7ed438 authored by ryanw's avatar ryanw

Assignment upload

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>ZooProgram</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
package program.zoo;
public class Animal
{
private String name;
private int age;
private double weight;
private String description;
private String animalClass;
private String environment;
private String feed;
public Animal(String name, int age, double weight, String description, String animalClass, String environment, String feed) {
this.name = name;
this.age = age;
this.weight = weight;
this.description = description;
this.animalClass = animalClass;
this.environment = environment;
this.feed = feed;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public double getWeight() {
return weight;
}
public String getDescription() {
return description;
}
public String getAnimalClass() {
return animalClass;
}
public String getEnvironment() {
return environment;
}
public String getFeed() {
return feed;
}
//method to print the details of an animal
public void printAnimal()
{
System.out.println("Animal details: " +
"\nName: " + name +
"\nAge: " + age +
"\nWeight: " + weight + "Kg" +
"\nDescription: " + description +
"\nClass: " + animalClass +
"\nEnvironment: " + environment +
"\nFood type: " + feed);
}
}
package program.zoo;
public class Apes extends Mammal
{
private String apeType;
public Apes(String name, int age, double weight, String description, String animalClass, String environment,
String feed, String fur, String furColour, String ears, String apeType)
{
super(name, age, weight, description, animalClass, environment, feed, fur, furColour, ears);
this.apeType = apeType;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Ape type: " + apeType +
"\n----------\n");
}
}
package program.zoo;
public class BigCat extends Mammal
{
private String catType;
public BigCat(String name, int age, double weight, String description, String animalClass, String environment,
String feed, String fur, String furColour, String ears, String catType)
{
super(name, age, weight, description, animalClass, environment, feed, fur, furColour, ears);
this.catType = catType;
}
//override of print animal from animal class
//to print full animal details
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Cat type: " + catType +
"\n----------\n");
}
}
package program.zoo;
public class Bird extends Animal
{
private double wingSpan;
private String beakType;
private boolean migratory;
private boolean flying;
public Bird(String name, int age, double weight, String description, String animalClass, String environment,
String feed, double wingSpan, String beakType, boolean migratory, boolean flying)
{
super(name, age, weight, description, animalClass, environment, feed);
this.wingSpan = wingSpan;
this.beakType = beakType;
this.migratory = migratory;
this.flying = flying;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Wing span: " + wingSpan +
"\nBeak type: " + beakType +
"\nMigratory: " + migratory +
"\nIs bird type flying: " + flying);
}
}
package program.zoo;
public class BirdsOfPray extends Bird {
private String birdType;
public BirdsOfPray(String name, int age, double weight, String description, String animalClass, String environment,
String feed, double wingSpan, String beakType, boolean migratory, boolean flying, String birdType)
{
super(name, age, weight, description, animalClass, environment, feed, wingSpan, beakType, migratory, flying);
this.birdType = birdType;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("\nBird Type: " + birdType +
"\n----------\n");
}
}
package program.zoo;
public class Crocodile extends Reptile
{
private String crocType;
public Crocodile(String name, int age, double weight, String description, String animalClass, String environment,
String feed, String movement, String scaleType, String scaleColour, String crocType)
{
super(name, age, weight, description, animalClass, environment, feed, movement, scaleType, scaleColour);
this.crocType = crocType;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Crocodile type: " + crocType +
"\n----------\n");
}
}
package program.zoo;
public class Fish extends Animal {
private double length;
private String colour;
private boolean freshWater;
private boolean saltWater;
public Fish(String name, int age, double weight, String description, String animalClass, String environment,
String feed, double length, String colour, boolean freshWater, boolean saltWater)
{
super(name, age, weight, description, animalClass, environment, feed);
this.length = length;
this.colour = colour;
this.freshWater = freshWater;
this.saltWater = saltWater;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Length: " + length + "ft" +
"\nColour: " + colour +
"\nWater type: " +
"\nFresh Water: " + freshWater +
"\nSalt Water: " + saltWater);
}
}
package program.zoo;
import java.util.Scanner;
public class Main {
private static ZooList animalList = new ZooList();
private static Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
//instantiating the animal store method from the ZooList class
animalList.animalStore();
//main menu will loop until exit is selected
boolean exit = false;
int choice = 0;
showMainMenu();
while (!exit)
{
System.out.println("\n0 to show menu options");
System.out.print("Enter menu choice: ");
choice = input.nextInt();
switch (choice) {
case 0:
showMainMenu();
break;
case 1:
animalList.getAnimalList();//method in zoo list class
break;
case 2:
animalList.allDetails();//method in zoo list class
break;
case 3:
seeIndividualDetails();
break;
case 4:
animalsByType();
break;
case 5:
foodRequirements();
break;
case 6:
animalsByEnvironment();
break;
case 7:
System.out.println("Thank you for using the Zoo Information center");
exit = true;
break;
default:
break;
}
}
}
//method prints out menu options
public static void showMainMenu()
{
System.out.println("Welcome to the Zoo Details center");
System.out.println("\nPlease select from the following options: ");
System.out.println("\n1 - View List of all animals."
+ "\n2 - View details of all animals."
+ "\n3 - View selected animal details"
+ "\n4 - View animals by type"
+ "\n5 - View animals food requirments"
+ "\n6 - View animals by environment"
+ "\n7 - Exit the application");
}
//method used to retrieve and print individual animal details
private static void seeIndividualDetails()
{
System.out.println("\nPlease select animal to view from the following: ");
animalList.getAnimalList();
System.out.println("\nEnter choice: ");
int choice = input.nextInt();
switch (choice) {
case 1:
ZooList.getTiger();
break;
case 2:
ZooList.getLion();
break;
case 3:
ZooList.getSilverback();
break;
case 4:
ZooList.getGibbon();
break;
case 5:
ZooList.getClownFish();
break;
case 6:
ZooList.getKoranAngel();
break;
case 7:
ZooList.getGreatWhite();
break;
case 8:
ZooList.getHammerHead();
break;
case 9:
ZooList.getFalcon();
break;
case 10:
ZooList.getOwl();
break;
case 11:
ZooList.getLark();
break;
case 12:
ZooList.getFinch();
break;
case 13:
ZooList.getPython();
break;
case 14:
ZooList.getBoa();
break;
case 15:
ZooList.getNile();
break;
case 16:
ZooList.getFreshWater();
break;
default:
break;
}
}
//method to print a list of animals by selected animal class
private static void animalsByType()
{
System.out.println("Current catagory list of animals in the zoo:"
+ "\nMammal"
+ "\nFish"
+ "\nBird"
+ "\nReptile");
System.out.print("Please type the catagory you wish to view: ");
String choice = input.next();
animalList.getCategory(choice);
}
//method to print out a full list of food
//or print food by animal class
private static void foodRequirements()
{
System.out.println("Please select from the following:"
+ "\n1 - View food for all animals"
+ "\n2 - View food for a catagory");
int choice = input.nextInt();
if (choice == 1)
{
animalList.printFeed();
}
if(choice == 2)
{
System.out.println("Please type a category from the following: "
+ "\nMammal"
+ "\nFish"
+ "\nBird"
+ "\nReptile");
System.out.print("Enter: ");
String cat = input.next();
animalList.findCategory(cat);
}
}
//method to print a list of animals by selected environment
private static void animalsByEnvironment()
{
System.out.println("We have animals from the following environments:"
+ "\nJungle"
+ "\nDesert"
+ "\nFresh water"
+ "\nSea"
+ "\nCountryside"
+ "\nGrassland"
+ "\nWoodland");
System.out.println("Please type the category you wish to veiw");
System.out.print("Enter: ");
String choice = input.next();
animalList.getEnviro(choice);
}
}
package program.zoo;
public class Mammal extends Animal
{
private String fur;
private String furColour;
private String ears;
public Mammal(String name, int age, double weight, String description, String animalClass, String environment,
String feed, String fur, String furColour, String ears)
{
super(name, age, weight, description, animalClass, environment, feed);
this.fur = fur;
this.furColour = furColour;
this.ears = ears;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Fur: " + fur +
"\nFur colour: " + furColour +
"\nEars: " + ears);
}
}
package program.zoo;
public class Reptile extends Animal {
private String movement;
private String scaleType;
private String scaleColour;
public Reptile(String name, int age, double weight, String description, String animalClass, String environment,
String feed, String movement, String scaleType, String scaleColour)
{
super(name, age, weight, description, animalClass, environment, feed);
this.movement = movement;
this.scaleType = scaleType;
this.scaleColour = scaleColour;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Movement type: " + movement +
"\nScale type: " + scaleType +
"\nScale colour: " + scaleColour);
}
}
package program.zoo;
public class Sharks extends Fish{
private String sharkType;
public Sharks(String name, int age, double weight, String description, String animalClass, String environment,
String feed, double length, String colour, boolean freshWater, boolean saltWater, String sharkType)
{
super(name, age, weight, description, animalClass, environment, feed, length, colour, freshWater, saltWater);
this.sharkType = sharkType;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Fish type: " + sharkType +
"\n----------\n");
}
}
package program.zoo;
public class Snake extends Reptile{
private String snakeType;
public Snake(String name, int age, double weight, String description, String animalClass, String environment,
String feed, String movement, String scaleType, String scaleColour, String snakeType)
{
super(name, age, weight, description, animalClass, environment, feed, movement, scaleType, scaleColour);
this.snakeType = snakeType;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Snake type: " + snakeType +
"\n----------\n");
}
}
package program.zoo;
public class SongBirds extends Bird{
private String songBirdType;
public SongBirds(String name, int age, double weight, String description, String animalClass, String environment,
String feed, double wingSpan, String beakType, boolean migratory, boolean flying, String songBirdType)
{
super(name, age, weight, description, animalClass, environment, feed, wingSpan, beakType, migratory, flying);
this.songBirdType = songBirdType;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Bird Type: " + songBirdType +
"\n----------\n");
}
}
package program.zoo;
public class TropicalFish extends Fish {
private String tropicalType;
public TropicalFish(String name, int age, double weight, String description, String animalClass, String environment,
String feed, double length, String colour, boolean freshWater, boolean saltWater, String tropicalType)
{
super(name, age, weight, description, animalClass, environment, feed, length, colour, freshWater, saltWater);
this.tropicalType = tropicalType;
}
@Override
public void printAnimal()
{
super.printAnimal();
System.out.println("Fish type: " + tropicalType +
"\n----------\n");
}
}
package program.zoo;
import java.util.ArrayList;
public class ZooList
{
//create arraylist of type animal to store and animals in
private static ArrayList<Animal>animalList = new ArrayList<Animal>();
private static ArrayList<Animal>animalQuery = new ArrayList<Animal>();
//initialising zoo animals
//animal objects then created animalStore() method
private static BigCat tiger;
private static BigCat lion;
private static Apes silverback;
private static Apes gibbon;
private static TropicalFish clownFish;
private static TropicalFish koranAngel;
private static Sharks greatWhite;
private static Sharks hammerHead;
private static BirdsOfPray falcon;
private static BirdsOfPray owl;
private static SongBirds lark;
private static SongBirds finch;
private static Snake python;
private static Snake boa;
private static Crocodile nile;
private static Crocodile freshWater;
//method to contain all animal objects
public void animalStore()
{
tiger = new BigCat("Larry", 4, 200,
"Big cat from a jungle",
"Mammal",
"Jungle",
"Meat",
"Hair",
"Orange, black stripes",
"Short ears",
"Bengal Tiger");
animalList.add(tiger);
lion = new BigCat("Nigel", 2, 170,
"Big cat from the sahara",
"Mammal",
"Grassland",
"Meat",
"Hair",
"Yellow, tan",
"Short ears",
"African Lion");
animalList.add(lion);
silverback = new Apes("Julius", 10, 200,
"A silverback from Africa",
"Mammal",
"Jungle",
"Foliage",
"Hair",
"Black and silver",
"Short ears",
"Mountain gorilla");
animalList.add(silverback);
gibbon = new Apes("Commodus", 5, 5,
"A gibbon from Vietnam",
"Mammal",
"Jungle",
"Foliage",
"Hair",
"Black",
"Short ears",
"Black crested gibbon");
animalList.add(gibbon);
clownFish = new TropicalFish("Augustus", 3, 0.25,
"A fish from the sea",
"Fish",
"Sea",
"Meat",
4,
"Orange with balck and white bands",
false,
true,
"Percula clownfish");
animalList.add(clownFish);
koranAngel = new TropicalFish("Domitian", 1, 1.2,
"Also a fish from the sea",
"Fish",
"Sea",
"meat",
11.5,
"Blue with white bands",
false,
true,
"Angel fish");
animalList.add(koranAngel);
greatWhite = new Sharks("Hadrian", 7, 750,
"Apex predator of the seas",
"Fish",
"Sea",
"Fish",
17,
"Gray/blue and white",
false,
true,
"Mackerel shark");
animalList.add(greatWhite);
hammerHead = new Sharks("Otho", 5, 75.5,
"Like a hammer but in the sea",
"Fish",
"Sea",
"Fish",
12,
"Silver",
false,
true,
"Scalloped hammerhead");
animalList.add(hammerHead);
falcon = new BirdsOfPray("maximus", 3, 1.2,
"Fastest member of the animal kingdom",
"Bird",
"Contryside",
"Meat",
110,
"Hooked beak",
true,
true,
"Peregine falcon");
animalList.add(falcon);
owl = new BirdsOfPray("Severus", 2, 1,
"Is a very large owl",
"Bird",
"Woodland",
"Meat",
140,
"Hooked beak",
false,
true,
"Great grey owl");
animalList.add(owl);
lark = new SongBirds("Galba", 3, 0.75,
"Often found larking around..",
"Bird",
"Grassland",
"Seed",
30,
"Straight pointed beak",
false,
true,
"Black eared sparrow-lark");
animalList.add(lark);
finch = new SongBirds("Pertinax", 4, 0.8,
"Sings a nice song",
"Bird",
"Woodland",
"Seed",
27,
"Straight pointed beak",
false,
true,
"Bullfinch");
animalList.add(finch);
python = new Snake("Nero", 10, 40,
"The animal not the coding language",
"Reptile",
"Jungle",
"Meat",
"lateral undulation",
"Small",
"Dark and light brown",
"Burmese python");
animalList.add(python);
boa = new Snake("Claudius", 5, 20,
"Classic constictor",
"Reptile",
"Jungle",
"Meat",
"lateral undulation",
"Small",
"Light brown and red",
"Red tailed boa");
animalList.add(boa);
nile = new Crocodile("Vespasian", 25, 600,
"Lived with the ancient egyptians",
"Reptile",
"Fresh water",
"Meat",
"Walking",
"Large",
"Green/grey",
"Nile crocodile");
animalList.add(nile);
freshWater = new Crocodile("Marcus", 12, 65,
"Live down under",
"Reptile",
"Fresh water",
"Meat",
"Walking",
"Large",
"Olive green and black",
"Fresh water crocodile");
animalList.add(freshWater);
}
//method to list animal food requirements
public void printFeed()
{
for (int i = 0; i < animalList.size(); i++)
{
System.out.println("Animal: " + animalList.get(i).getName() +
" Type: " + animalList.get(i).getAnimalClass() +
" Feed: " + animalList.get(i).getFeed());
}
}
//method searches for and returns animals in a selected environment
Animal getEnviro(String enviro)
{
for(Animal animal : animalList)
{
if(animal.getEnvironment().equalsIgnoreCase(enviro))
{
animalQuery.add(animal);
}
}
for(Animal animal : animalQuery)
{
System.out.println(animal.getName() + ": " + "Environment: " + animal.getEnvironment());
}
animalQuery.clear();
return null;
}
//method to search for a select animal type and
//stores then in the animalQuery array list then prints
//the animals from that list
Animal getCategory(String category)
{
for(Animal animal : animalList)
{
if(animal.getAnimalClass().equalsIgnoreCase(category))
{
animalQuery.add(animal);
}
}
for(Animal animal : animalQuery)
{
System.out.println(animal.getAnimalClass() + " - " + animal.getName());
}
animalQuery.clear();
return null;
}
//method to search and return selected food categories
Animal findCategory(String category)
{
for(Animal animal : animalList)
{
if(animal.getAnimalClass().equalsIgnoreCase(category))
{
animalQuery.add(animal);
}
}
for(Animal animal : animalQuery)
{
System.out.println(animal.getAnimalClass() + " - " + animal.getName() + " - " + animal.getFeed());
}
animalQuery.clear();
return null;
}
//method to display list of current animals
public ArrayList<Animal> getAnimalList()
{
System.out.println("Total animals in the zoo: " + animalList.size());
for (int i = 0; i < animalList.size(); i++)
{
System.out.println((i+1) + " - " + animalList.get(i).getName() + ", " + animalList.get(i).getDescription());
}
return animalList;
}
//method to print out a list of all animal details
public void allDetails()
{
tiger.printAnimal();
lion.printAnimal();
silverback.printAnimal();
gibbon.printAnimal();
clownFish.printAnimal();
koranAngel.printAnimal();
greatWhite.printAnimal();
hammerHead.printAnimal();
falcon.printAnimal();
owl.printAnimal();
lark.printAnimal();
finch.printAnimal();
python.printAnimal();
boa.printAnimal();
nile.printAnimal();
freshWater.printAnimal();
}
//get methods for displaying animal details
public static BigCat getTiger() {
tiger.printAnimal();
return tiger;
}
public static BigCat getLion() {
lion.printAnimal();
return lion;
}
public static Apes getSilverback() {
silverback.printAnimal();
return silverback;
}
public static Apes getGibbon() {
gibbon.printAnimal();
return gibbon;
}
public static TropicalFish getClownFish() {
clownFish.printAnimal();
return clownFish;
}
public static TropicalFish getKoranAngel() {
koranAngel.printAnimal();
return koranAngel;
}
public static Sharks getGreatWhite() {
greatWhite.printAnimal();
return greatWhite;
}
public static Sharks getHammerHead() {
hammerHead.printAnimal();
return hammerHead;
}
public static BirdsOfPray getFalcon() {
falcon.printAnimal();
return falcon;
}
public static BirdsOfPray getOwl() {
owl.printAnimal();
return owl;
}
public static SongBirds getLark() {
lark.printAnimal();
return lark;
}
public static SongBirds getFinch() {
finch.printAnimal();
return finch;
}
public static Snake getPython() {
python.printAnimal();
return python;
}
public static Snake getBoa() {
boa.printAnimal();
return boa;
}
public static Crocodile getNile() {
nile.printAnimal();
return nile;
}
public static Crocodile getFreshWater() {
freshWater.printAnimal();
return freshWater;
}
}
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