Commit b19275fb authored by Suleman Hussain's avatar Suleman Hussain

finish

parent fd7f6dc2
File added
public class animal {
String name;
String habitat;
String diet;
String des;
String extra;
public animal(){
name="";
habitat="";
diet="";
des="";
extra="";
}
public animal(String input_name, String input_habitat, String input_diet, String input_des){
name = input_name;
habitat = input_habitat;
diet = input_diet;
des = input_des;
extra="";
}
public String getName(){return name;}
public String getDiet(){return diet;}
public String gethabitat(){return habitat;}
public String getDesc(){return des;}
public String getExtra(){return extra;}
}
\ No newline at end of file
public class bird extends animal{
boolean flight;
public bird(){
super();
flight=true;
}
public bird(String input_name, String input_envi, String input_diet, String input_des, Boolean input_flight){
name= input_name;
habitat=input_envi;
diet=input_diet;
des=input_des;
flight=input_flight;
if(flight){extra="flight";}
else{extra="flightless";}
}
}
\ No newline at end of file
public class fish extends animal{
boolean salt_water;
public fish(){
super();
salt_water=true;
}
public fish(String input_name, String input_envi, String input_diet, String input_des, Boolean input_salt){
name= input_name;
habitat=input_envi;
diet=input_diet;
des=input_des;
salt_water=input_salt;
if(salt_water){extra="Salt water";}
else{extra="Fresh water";}
}
}
\ No newline at end of file
File added
import java.util.Scanner;
public class main {
public static void main(String[] args) throws Exception {
zoo York_zoo=new zoo("York Zoo");
mamal goat=new mamal("Bob","mountains","grass","resting",true);
mamal lion=new mamal("Alex","grasslands","meat","sleeping",true);
mamal capybara=new mamal("Helen","swamp","grass","swimming",false);
bird owl=new bird("Winnie","Forrests","mice","Wise",true);
bird ostridge=new bird("Barry","savanna","plants","running",false);
bird penguin=new bird("Mumble","Frozen oceans","fish","resting",false);
fish shark=new fish("Bruce", "Ocean", "Fish", "Hungry",true);
fish clownfish=new fish("Nemo","Ocean","algae","hiding",true);
fish trout=new fish("Geof","Rivers","shrimp","happy",false);
reptile scorpion=new reptile("Fez","Desert","insects","burrowing",true);
reptile snake=new reptile("mik","forrest","rats","sleeping",false);
reptile turtles=new reptile("Rapheal","ocean","sardines","happy",false);
York_zoo.addAnimal(goat);
York_zoo.addAnimal(lion);
York_zoo.addAnimal(capybara);
York_zoo.addAnimal(owl);
York_zoo.addAnimal(ostridge);
York_zoo.addAnimal(penguin);
York_zoo.addAnimal(shark);
York_zoo.addAnimal(clownfish);
York_zoo.addAnimal(trout);
York_zoo.addAnimal(scorpion);
York_zoo.addAnimal(snake);
York_zoo.addAnimal(turtles);
York_zoo.displayAllAnimalDetails();
York_zoo.displayByhabitat("swamp");
York_zoo.displayFoodRequired();
York_zoo.displayAnimalDetails(clownfish);
}
}
public class mamal extends animal{
boolean land;
public mamal(){
super();
land=true;
}
public mamal(String input_name, String input_envi, String input_diet, String input_des, Boolean input_land){
name= input_name;
habitat=input_envi;
diet=input_diet;
des=input_des;
land=input_land;
if(land){extra="Land";}
else{extra="Water";}
}
}
\ No newline at end of file
public class reptile extends animal{
boolean poisonous;
public reptile(){
super();
poisonous=true;
}
public reptile(String input_name, String input_envi, String input_diet, String input_des, Boolean input_poisonous){
name= input_name;
habitat=input_envi;
diet=input_diet;
des=input_des;
poisonous=input_poisonous;
if(poisonous){extra="poisonous";}
else{extra="non-poisonous";}
}
}
\ No newline at end of file
File added
import java.util.ArrayList;
public class zoo{
String name;
ArrayList<animal> main_list = new ArrayList<animal>();
ArrayList<animal> mamal_list = new ArrayList<animal>();
ArrayList<animal> bird_list = new ArrayList<animal>();
ArrayList<animal> fish_list = new ArrayList<animal>();
ArrayList<animal> reptile_list = new ArrayList<animal>();
public zoo(){
name="No name";
}
public zoo(String input_name){
name=input_name;
}
public void addAnimal(animal tempAnimal){main_list.add(tempAnimal);};
public void displayAllAnimalDetails(){
for(int i = 0; i<main_list.size(); i++){
System.out.println("Name: "+ main_list.get(i).getName() + ", habitat: " + main_list.get(i).gethabitat() + ", Food: " + main_list.get(i).getDiet() + ", Description: " + main_list.get(i).getDesc() + ", Extra: " + main_list.get(i).getExtra());
}
}
public void displayAnimalDetails(animal tempAnimal){
System.out.println("Name: "+ tempAnimal.getName() + ", habitat: " + tempAnimal.gethabitat() + ", Food: " + tempAnimal.getDiet() + ", Description: " + tempAnimal.getDesc() + ", Extra: " + tempAnimal.getExtra());
}
public void generateListByType(String animalType){
for(int i = 0; i<main_list.size(); i++){
if (main_list.get(i) instanceof mamal) {mamal_list.add(main_list.get(i));}
else if (main_list.get(i) instanceof bird) {bird_list.add(main_list.get(i));}
else if (main_list.get(i) instanceof reptile) {reptile_list.add(main_list.get(i));}
else if (main_list.get(i) instanceof fish) {fish_list.add(main_list.get(i));}
}
}
public void displayFoodRequired(){
for(int i = 0; i < main_list.size(); i++){
System.out.print(main_list.get(i).getName() + ": " + main_list.get(i).getDiet() + ", ");
}
System.out.println();
}
public void displayByhabitat(String input_habitat){
for(int i = 0; i<main_list.size(); i++){
if (main_list.get(i).gethabitat() == input_habitat){System.out.println(main_list.get(i).getName());}
}
}
}
\ No newline at end of file
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