Commit 971cd66d authored by Gabriel Penman's avatar Gabriel Penman

zoo application

parents
File added
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
File added
File added
File added
File added
File added
File added
File added
panda,apple,2,banana,2,bamboo,96
rodent,peanut,15,humanflesh,15,grain,50,apple,10,banana,10
ant,apple,20,banana,20,grain,20,honey,20,peanut,20
parrot,worms,30,seeds,20,apple,20,grain,20,banana,10
\ No newline at end of file
apple,53
banana,43
peanut,120
bamboo,2
humanflesh,130
grain,30
honey,23
worms,90
seeds,40
\ No newline at end of file
desert,50
ice,0
grassland,30
urban,15
marsh,25
jungle,35
\ No newline at end of file
Diet.csv goes in format food, percentage, food, percentage, food, percentage
\ No newline at end of file
import java.util.Arrays;
public abstract class Animal {
private String givenName;
private String commonName;
private Integer age;
private Boolean sex;
private String[] taxonomy = {"","","","","","","",""};
private Diet diet;
private double baseRCI;
private Habitat habitat;
public String getGivenName() {
return givenName;
}
public String getCommonName() {return this.commonName;}
public Integer getAge() {return this.age;}
public Boolean getSex() {return this.sex;}
public Habitat getHabitat() {return habitat;}
public String getSexString() {
if (this.getSex()) {
return "Male";
} else {
return "Female";
}
}
public String[] getTaxonomy() {return this.taxonomy;}
public Diet getDiet() {return this.diet;}
public String getTaxonomyString() {
return Arrays.toString(this.getTaxonomy());
}
public double getBaseRCI() {
return this.baseRCI;
}
public double getWeeklyBaseRCI() {
return this.baseRCI*7;
}
public double getCalories() {
return this.baseRCI;
}
public double getWeeklyCalories(){
return this.getCalories()*7;
}
public void setGivenName(String givenName) {
this.givenName = givenName;
}
public void setCommonName(String commonName) {this.commonName = commonName;}
public void setAge(Integer age) {this.age = age;}
public void setSex(Boolean sex) {this.sex = sex;}
public void setTaxonomy(String[] taxonomy) {this.taxonomy = taxonomy;}
public void setDiet(Diet diet) {this.diet = diet;}
public void setBaseRCI(double baseRCI) {this.baseRCI = baseRCI;}
public void setHabitat(Habitat habitat) {this.habitat = habitat;}
public Animal(String commonName, Integer age, Boolean sex, String[] taxonomy, Diet diet, double baseRCI, Habitat habitat, String givenName) {
this.setCommonName(commonName);
this.setAge(age);
this.setSex(sex);
this.setTaxonomy(taxonomy);
this.setDiet(diet);
this.setBaseRCI(baseRCI);
this.setHabitat(habitat);
this.setGivenName(givenName);
}
public Animal(String commonName, Integer age, Boolean sex, String[] taxonomy, Diet diet, double baseRCI, Habitat habitat) {
this.setCommonName(commonName);
this.setAge(age);
this.setSex(sex);
this.setTaxonomy(taxonomy);
this.setDiet(diet);
this.setBaseRCI(baseRCI);
this.setHabitat(habitat);
this.setGivenName("Unnamed");
}
public final String basicDetails() {
String string = "Given name: "+this.getGivenName()+"\n"+
"Common name: "+this.getCommonName()+"\n"+
"Age: "+this.getAge()+"\n"+
"Sex: "+this.getSexString()+"\n"+
"Habitat: "+this.getHabitat()+"\n"+
"RCI: "+this.getBaseRCI()+"\n";
return string;
}
public final String taxonomyAndDiet() {
String string = "Taxonomy:\n\n-- Kingdom -- Phylum -- Class -- Order -- Family -- Genus -- Species --\n"+this.getTaxonomyString()+"\n\n"+
"Diet: "+this.getDiet().toString();
return string;
}
public abstract String additionalDetails();
public final String details() {
return this.basicDetails()+this.additionalDetails()+this.taxonomyAndDiet();
}
}
File added
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Initilizing!\n");
Storage storage = new Storage("/Users/Penman/Desktop/zoo/lib/food.csv", "/Users/Penman/Desktop/zoo/lib/habitat.csv", "/Users/Penman/Desktop/zoo/lib/diet.csv");
Zoo zoo = new Zoo();
zoo.allAnimalsAdd( new _Panda("Gabriel",20,true, storage));
zoo.allAnimalsAdd( new _Panda("Sarah",21,false, storage));
_Panda littleJim = new _Panda("Little Jim",2,true, storage);
littleJim.setBaseRCI(400);
zoo.allAnimalsAdd(littleJim);
zoo.allAnimalsAdd( new _Rat("Kieran",2,true, storage));
zoo.allAnimalsAdd( new _Rat("Mary",1,false, storage));
zoo.allAnimalsAdd( new _Capybara("Leah",12,false, storage));
zoo.allAnimalsAdd( new _Capybara("Robert",16,true, storage));
zoo.allAnimalsAdd( new _Capybara("Jack",32,true, storage));
// Polymorphic ants
zoo.allAnimalsAdd( new _Leafcutter(false,"Queen",storage));
for (int i = 0; i < 129; i++) {
zoo.allAnimalsAdd( new _Leafcutter(false,"Worker",storage));
}
for (int i = 0; i < 12; i++) {
zoo.allAnimalsAdd( new _Leafcutter(false,"Soldier",storage));
}
zoo.allAnimalsAdd(new _ScarletMacaw("Jules", 20, false, 1.3, storage));
zoo.allAnimalsAdd(new _ScarletMacaw("Kitty", 21, true, 1.5, storage));
zoo.allAnimalsAdd(new _GreyParrot("Jojo", 9, true, 1.2, storage));
zoo.allAnimalsAdd(new _GreyParrot("Elaine", 43, true, 1.1, storage));
Menu menu = new Menu();
menu.main(zoo);
}
}
\ No newline at end of file
File added
import java.util.ArrayList;
public class Diet {
private final String NAME;
private final ArrayList<DietItem> DIET;
public String getName() {
return this.NAME;
}
public ArrayList<DietItem> getContent() {
return this.DIET;
}
private Boolean checkDiet(ArrayList<DietItem> diet) {
//Checks to see if the percentages match up
double total = 0;
for (DietItem item : diet) {
total = total+item.getDietPercentage();
}
if (total == 100) {
return true;
} else {
return false;
}
}
public Diet(String name, DietItem... args) throws Exception {
this.NAME = name;
ArrayList<DietItem> diet = new ArrayList<DietItem>();
//Adds all DietItem args to an arraylist called diet
for (DietItem arg : args) {
diet.add(arg);
}
//Checks to see if the percentages match up
if (this.checkDiet(diet)) {
//Sets constant diet to the new diet
this.DIET = diet;
} else {
throw new Exception("DIETPERCENTAGE of all dietItems does not total to 100");
}
}
public Diet(String name, ArrayList<DietItem> diet) throws Exception {
this.NAME = name;
if (this.checkDiet(diet)) {
this.DIET = diet;
} else {
throw new Exception("DIETPERCENTAGE of all dietItems does not total to 100");
}
}
public String toString() {
String string = this.getName().substring(0, 1).toUpperCase() + this.getName().substring(1);
for (DietItem dietItem : this.getContent()) {
string += "\n "+dietItem.toString();
}
return string;
}
}
public class DietItem {
private final Food FOOD;
private final double DIETPERCENTAGE;
public Food getFood() {
return this.FOOD;
}
public double getDietPercentage() {
return this.DIETPERCENTAGE;
}
public DietItem(Food food, double dietPercentage) {
this.FOOD = food;
this.DIETPERCENTAGE = dietPercentage; // Calories per kilogram
}
public String toString() {
return this.getFood().toString()+" | Percentage of diet: "+this.getDietPercentage()+"%";
}
}
File added
public class Food {
private final String NAME;
private final double ENERGYDENSITY; // Calories per kilogram
private double amount = 0;
public double getEnergyDensity() {
return this.ENERGYDENSITY;
}
public String getName(){
return this.NAME;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public Food(String name, double energyDensity) {
this.NAME = name;
this.ENERGYDENSITY = energyDensity;
}
public Food(Food food) {
this.NAME = food.getName();
this.ENERGYDENSITY = food.getEnergyDensity();
this.amount = food.getAmount();
}
public String toString() {
String string;
if (this.getAmount() != 0) {
string = "Name: "+this.getName().substring(0, 1).toUpperCase() + this.getName().substring(1)+" | Amount: "+Math.round(this.getAmount())+"kg";
} else {
string = "Name: "+this.getName().substring(0, 1).toUpperCase() + this.getName().substring(1)+" | Energy density: "+this.getEnergyDensity()+"cal/kg";
}
return string;
}
}
public class Habitat {
private final String name;
private double averageTemp;
public String getName(){
return this.name;
}
public double getAverageTemp() {
return averageTemp;
}
public void setAverageTemp(double averageTemp) {
this.averageTemp = averageTemp;
}
public Habitat(String name, double averageTemp) {
this.name = name;
this.averageTemp = averageTemp;
}
public String toString() {
String string;
string = "Name: "+this.getName().substring(0, 1).toUpperCase() + this.getName().substring(1)+" | AverageTemperature: "+this.getAverageTemp();
return string;
}
}
File added
import java.util.ArrayList;
import java.util.Scanner;
public class Menu {
private ArrayList<Animal> selection = new ArrayList<Animal>();
public ArrayList<Animal> getSelection() {
return this.selection;
}
public void setSelection(ArrayList<Animal> selection) {
this.selection = selection;
}
public void addSelection(Animal toAdd) {
Boolean duplicate = false;
for (Animal animal : this.getSelection()) {
if (animal.equals(toAdd)) {
duplicate = true;
}
}
if (duplicate == false) {
this.getSelection().add(toAdd);
}
}
public Boolean confirmSelection(ArrayList<Animal> selection) {
Boolean run = true;
Boolean var = true;
System.out.println("\n-----------------------\n");
while (run) {
System.out.println("1. Add to selection\n2. Add to selection and finish\n3. Discard\n");
Scanner scanner = new Scanner(System.in);
String choice = scanner.nextLine();
int c;
try {
c = Integer.parseInt(choice);
} catch (Exception e) {
c = 0;
}
if (c == 1 || c == 2) {
for (Animal animal : selection) {
this.addSelection(animal);
}
System.out.println("# "+this.getSelection().size()+" animals selected. #\n");
run = false;
}
if (c == 2) {
var = false;
}
if (c == 3) {
System.out.println("Discarded selection.\n");
run = false;
}
if (c < 1 || c > 3) {
System.out.println("Invalid choice.\n");
}
}
return var;
}
public void main(Zoo zoo){
Scanner scanner = new Scanner(System.in);
String string = "-----------------------\n\nMain menu: "+this.getSelection().size()+" animals selected \n\n";
string += "1. Select all animals in Zoo\n";
string += "2. Select a specific animal by animal name\n";
string += "3. Select a specific animal by given name\n";
string += "4. Select a specific animal by enviroment\n";
string += "5. Display weekly food requirements for selection\n";
string += "6. Display details for selection\n";
string += "7. Deselect\n";
System.out.println(string);
String choice = scanner.nextLine();
System.out.println("\n-----------------------\n");
int c;
try {
c = Integer.parseInt(choice);
} catch (Exception e) {
c = 0;
}
switch (c) {
case (0): {
System.out.println("Invalid choice, type a number.\n");
break;
}
case (1): {
this.setSelection(zoo.getAllAnimals());
System.out.println("# "+this.getSelection().size()+" animals selected. #\n");
break;
}
case (2): {
Boolean run = true;
while (run) {
System.out.println("Search animals: Type / to exit.\n");
String subchoice = scanner.nextLine().toLowerCase();
if (subchoice.equals("/")){
run = false;
break;
}
ArrayList<Animal> animals = zoo.getAllAnimals();
ArrayList<Animal> found = new ArrayList<Animal>();
for (Animal animal : animals) {
if (animal.getCommonName().toLowerCase().contains(subchoice)) {
found.add(animal);
}
}
System.out.println("\n-----------------------\n");
if (found.size() == 1) {
System.out.println("Match found with name: "+found.get(0).getCommonName());
run = this.confirmSelection(found);
}
if (found.size() > 1) {
System.out.println("Multiple matches found:\n");
found.sort((o1, o2) -> o1.getCommonName().compareTo(o2.getCommonName()));
int amount = 0;
for (int i = 0; i < found.size(); i++) {
if (i == 0 || found.get(i).getCommonName().equals(found.get(i-1).getCommonName())) {
amount += 1;
} else {
if (amount == 1 || amount == 0) {
System.out.println("1 "+found.get(i-1).getCommonName());
} else {
System.out.println(amount+" "+found.get(i-1).getCommonName()+"s");
}
amount = 0;
}
}
if (amount == 1) {
System.out.println("1 "+found.get(found.size()-1).getCommonName());
} else {
System.out.println(amount+" "+found.get(found.size()-1).getCommonName()+"s");
}
run = this.confirmSelection(found);
}
if (found.size() == 0) {
System.out.println("Sorry no matches, perhaps try a shorter string. Press enter to see all animals.");
}
}
break;
}
case (3): {
Boolean run = true;
while (run) {
System.out.println("Search animals by name: Type / to exit.\n");
String subchoice = scanner.nextLine().toLowerCase();
if (subchoice.equals("/")){
run = false;
break;
}
ArrayList<Animal> animals = zoo.getAllAnimals();
ArrayList<Animal> found = new ArrayList<Animal>();
for (Animal animal : animals) {
if (animal.getGivenName().toLowerCase().contains(subchoice)) {
found.add(animal);
}
}
System.out.println("\n-----------------------\n");
if (found.size() == 1) {
System.out.println("Match found with name: "+found.get(0).getGivenName());
}
if (found.size() > 1) {
found.sort((o1, o2) -> o1.getCommonName().compareTo(o2.getCommonName()));
System.out.println("Multiple matches found:\n");
int amount = 0;
for (int i = 0; i < found.size(); i++) {
if (i == 0 || found.get(i).getGivenName().equals(found.get(i-1).getGivenName())) {
amount += 1;
} else {
if (amount == 1 || amount == 0) {
System.out.println(found.get(i-1).getGivenName());
} else {
System.out.println(amount+" "+found.get(i-1).getGivenName()+"s");
}
amount = 0;
}
}
if (amount == 1 || amount == 0) {
System.out.println(found.get(found.size()-1).getGivenName());
} else {
System.out.println(amount+" "+found.get(found.size()-1).getGivenName()+"s");
}
}
if (found.size() == 0) {
System.out.println("Sorry no matches, perhaps try a shorter string. Press enter to see all animals.");
} else {
run = this.confirmSelection(found);
}
}
break;
}
case (4): {
Boolean run = true;
while (run) {
//repeated code !
System.out.println("Search enviroments: Type / to exit.\n");
String subchoice = scanner.nextLine().toLowerCase();
if (subchoice.equals("/")){
run = false;
break;
}
ArrayList<Animal> animals = zoo.getAllAnimals();
ArrayList<Animal> found = new ArrayList<Animal>();
for (Animal animal : animals) {
if (animal.getHabitat().getName().toLowerCase().contains(subchoice)) {
found.add(animal);
}
}
System.out.println("\n-----------------------\n");
if (found.size() > 0) {
System.out.println("Habitats found:\n");
ArrayList<Habitat> habitats = new ArrayList<Habitat>();
for (int i = 0; i < found.size(); i++) {
Habitat habitat = found.get(i).getHabitat();
if (habitats.contains(habitat)==false) {
habitats.add(habitat);
}
}
for (Habitat habitat : habitats) {
System.out.println(habitat);
}
run = this.confirmSelection(found);
}
if (found.size() == 0) {
System.out.println("Sorry no matches, perhaps try a shorter string. Press enter to see all habitats.");
}
}
break;
}
case (5): {
if (this.getSelection().size() == 0) {
System.out.println("No selection.\n");
} else
{
System.out.println(zoo.foodArrayToString(zoo.totalFood(this.getSelection())));
}
break;
}
case (6): {
if (this.getSelection().size() == 0) {
System.out.println("No selection.\n");
} else
{
System.out.println(zoo.animalArrayToString(this.getSelection()));
}
break;
}
case (7): {
this.setSelection(new ArrayList<Animal>());
break;
}
default: {
System.out.println("Choice not available! \n");
}
}
this.main(zoo);
}
}
File added
File added
import java.io. * ;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Storage {
private ArrayList<Food> food;
private ArrayList<Habitat> habitat;
private ArrayList<Diet> diet;
public ArrayList<Food> getFood() {
return this.food;
}
public ArrayList<Diet> getDiet() {
return this.diet;
}
public Diet findDiet(String dietName) {
Diet dietMatch = null;
for (Diet diet : this.getDiet()) {
if (diet.getName().equals(dietName)) {
dietMatch = diet;
}
}
return dietMatch;
}
public ArrayList<Habitat> getHabitat() {
return this.habitat;
}
public Habitat findHabitat(String habitatName) {
Habitat habitatMatch = null;
for (Habitat habitat : this.getHabitat()) {
if (habitat.getName().equals(habitatName)) {
habitatMatch = habitat;
}
}
return habitatMatch;
}
public Storage(String foodPath, String habitatPath, String dietPath) throws Exception {
this.food = importFood(foodPath);
this.habitat = importHabitat(habitatPath);
this.diet = importDiet(dietPath);
for (Food food : this.getFood()) {
System.out.println("Imported Food Object: "+food.toString());
}
for (Habitat habitat : this.getHabitat()) {
System.out.println("Imported Habitat Object: "+habitat.toString());
}
for (Diet diet : this.getDiet()) {
System.out.println("Imported Diet Object: "+diet.toString());
}
System.out.println("\n");
}
private ArrayList<Food> importFood(String foodPath) {
ArrayList<Food> foodObjs = new ArrayList<Food>();
ArrayList<String[]> foods = this.read(foodPath);
for (String[] item : foods) {
foodObjs.add(createFood(item));
}
return foodObjs;
}
private ArrayList<Habitat> importHabitat(String habitatPath) {
ArrayList<Habitat> habitatObjs = new ArrayList<Habitat>();
ArrayList<String[]> habitats = this.read(habitatPath);
for (String[] item : habitats) {
habitatObjs.add(createHabitat(item));
}
return habitatObjs;
}
private ArrayList<Diet> importDiet(String dietPath) throws Exception {
ArrayList<Diet> dietObjs = new ArrayList<Diet>();
ArrayList<String[]> diets = this.read(dietPath);
for (String[] item : diets) {
dietObjs.add(createDiet(item));
}
return dietObjs;
}
private Food createFood(String[] item) {
Food food = new Food(item[0], Double.parseDouble(item[1]));
return food;
}
private Habitat createHabitat(String[] item) {
Habitat habitat = new Habitat(item[0], Double.parseDouble(item[1]));
return habitat;
}
private Diet createDiet(String[] item) throws Exception {
ArrayList<DietItem> dietItems = new ArrayList<DietItem>();
Food matchedFood = null;
//take head off of item
String dietName = item[0];
//remove head
String[] copy = new String[item.length - 1];
for (int i = 0, j = 0; i < item.length; i++) {
if (i != 0) {
copy[j++] = item[i];
}
}
item = copy;
for (int index = 0; index < item.length; index++) {
if (index%2==0) {
// Pull foodname from the diet data
String foodName = item[index];
//Find matching food
for (Food food : this.getFood()) {
String cycledName = food.getName();
if (cycledName.equals(foodName)) {
matchedFood = food;
}
}
// not regestering match?
if (matchedFood == null) {
throw new Exception("Diet specified food not found in storage: "+foodName);
}
} else {
int percentage;
try {
percentage = Integer.parseInt(item[index]);
} catch (Exception e) {
System.out.println(item[index]);
throw new Exception("Problem converting percentage value to int");
}
dietItems.add(new DietItem(matchedFood, percentage));
matchedFood = null;
}
}
// need to instantiate diet class with DietItem objects passed from for loop
Diet diet = new Diet(dietName, dietItems);
return diet;
}
private ArrayList<String[]> read(String path) {
String line = "";
String splitBy = ",";
ArrayList<String[]> readItems = new ArrayList<String[]>();
try {
//parsing a CSV file into BufferedReader class constructor
BufferedReader br = new BufferedReader(new FileReader(path));
while ((line = br.readLine()) != null)
//returns a Boolean value
{
String[] item = line.split(splitBy);
readItems.add(item);
}
}
catch(IOException e) {
e.printStackTrace();
}
return readItems;
}
}
File added
import java.util.ArrayList; // import the ArrayList class
public class Zoo {
private ArrayList<Animal> allAnimals = new ArrayList<Animal>();
public ArrayList<Animal> getAllAnimals() {
return this.allAnimals;
}
public void allAnimalsAdd(Animal animal) {
this.getAllAnimals().add(animal);
}
public ArrayList<Food> foodRequired(Animal animal) {
double calories = animal.getWeeklyCalories();
Diet dietObject = animal.getDiet();
ArrayList<DietItem> diet = dietObject.getContent();
ArrayList<Food> foodRequired = new ArrayList<Food>();
for (DietItem item : diet) {
double proportionalCalories = (item.getDietPercentage()/100)*calories;
Food food = new Food(item.getFood());
double kilogramsRequired = proportionalCalories/food.getEnergyDensity();
food.setAmount(kilogramsRequired);
foodRequired.add(food);
}
return foodRequired;
}
public ArrayList<Food> totalFood(ArrayList<Animal> animalList) {
ArrayList<Food> totalFoodRequired = new ArrayList<Food>();
for (Animal animal : animalList) {
ArrayList<Food> foodRequired = this.foodRequired(animal);
for (Food food : foodRequired) {
totalFoodRequired.add(food);
}
}
// Joins food objects
ArrayList<Food> finalFood = new ArrayList<Food>();
for (Food food : totalFoodRequired) {
Boolean match = false;
double amount = 0;
Food carry = food;
for (Food second : finalFood) {
if (second.getName().equals(food.getName())){
match = true;
amount = food.getAmount();
carry = second;
break;
}
}
if (match) {
carry.setAmount(carry.getAmount()+amount);
} else {
finalFood.add(new Food(food));
}
}
return finalFood;
}
public String foodArrayToString(ArrayList<Food> array) {
String string = "";
for (Food food : array) {
string = string+food.toString()+"\n";
}
return string;
}
public String animalArrayToString(ArrayList<Animal> array) {
String string = "";
array.sort((o1, o2) -> o1.getCommonName().compareTo(o2.getCommonName()));
int amount = 0;
for (int i = 0; i < array.size(); i++) {
if ((i > 0) && (array.get(i).details().equals(array.get(i-1).details()))) {
amount = amount+1;
} else {
if (amount > 0) {
string = string+"\n ... and "+amount+" more identical animals.\n\n";
amount = 0;
}
string = string+array.get(i).details()+"\n\n";
}
}
if (amount > 0) {
string = string+"\n ... and "+amount+" more identical animals.\n\n";
amount = 0;
}
return string;
}
}
File added
public abstract class _Ant extends Animal {
private final String CASTE;
public String getCaste() {
return this.CASTE;
}
public _Ant(String antType, boolean sex, String caste, Habitat habitat, String genus, String species, Storage storage) {
super(antType, null, sex, new String[] {"Animalia","Arthropoda","Insecta","Hymenoptera","Formicidae",genus,species}, storage.findDiet("ant"),1, habitat);
this.CASTE = caste;
}
public String additionalDetails() {
return "Form: "+this.CASTE+"\n";
};
}
public class _Capybara extends Animal {
public _Capybara(String name, int age, boolean sex, Storage storage) throws Exception{
super("Capybara", age, sex, new String[] {"Animalia","Chordata","Mammalia","Rodentia","Caviidae","Hydrochoerus","H. hydrochaeris"}, storage.findDiet("rodent"),1000, storage.findHabitat("marsh"), name);
}
public String additionalDetails() {
return "";
};
}
public class _GreyParrot extends _Parrot {
public _GreyParrot(String name, int age, boolean sex, double span, Storage storage) {
super("GreyParrot", age, sex, span, "Grey", storage.findHabitat("jungle"), "Psittacus", "P. erithacus", storage, name);
}
}
public class _Leafcutter extends _Ant {
public _Leafcutter(boolean sex, String caste, Storage storage) {
super("Leafcutter ant", sex, caste, storage.findHabitat("jungle"), "Atta", "Sexdens", storage);
}
}
\ No newline at end of file
public class _Panda extends Animal {
public _Panda(String name, int age, boolean sex, Storage storage) throws Exception{
super("Panda", age, sex, new String[] {"Animalia","Chordata","Mammalia","Carnivora","Ursidae","Ailuropoda","A. melanoleuca"}, storage.findDiet("panda"),9000, storage.findHabitat("ice"), name);
}
public String additionalDetails() {
return "";
};
}
public abstract class _Parrot extends Animal {
private double span;
private final String COLOUR;
public double getSpan() {
return span;
}
public String getColour() {
return this.COLOUR;
}
public void setSpan(double span) {
this.span = span;
}
public _Parrot(String birdType, int age, boolean sex, double span, String colour, Habitat habitat, String genus, String species, Storage storage, String name) {
super(birdType, age, sex, new String[] {"Animalia","Chordata","Aves","Psittacopasserae","Psittaciformes",genus,species}, storage.findDiet("parrot"),220, habitat, name);
this.setSpan(span);
this.COLOUR = colour;
}
public String additionalDetails() {
return "Wingspan: "+this.span+"\n"+"Colour: "+this.COLOUR+"\n";
};
}
File added
public class _Rat extends Animal {
public _Rat(String name, int age, boolean sex, Storage storage) throws Exception{
super("Rat", age, sex, new String[] {"Animalia","Chordata","Mammalia","Simplicidentata","Muridae","Rattus","R. rattus"}, storage.findDiet("rodent"),60, storage.findHabitat("urban"), name);
}
public String additionalDetails() {
return "";
};
}
public class _ScarletMacaw extends _Parrot {
public _ScarletMacaw(String name, int age, boolean sex, double span, Storage storage) {
super("Scarelet Macaw", age, sex, span, "Scarlet", storage.findHabitat("jungle"), "Ara", "A. macao", storage, name);
}
}
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