Implement Zoo class (with its test class). Zoo have name and area in meter square. Zoo can have one or more Animals. An Animal has ID, name, Type, Age, gender. We should be able to add new Animals to the Zoo, remove Animals and determine how many animals currently in the zoo.
This is the Zoo class:
import java.util.ArrayList;
public class Zoo {
String name;
String area;
ArrayList<Animal> animals;
static int id;
public Zoo(String name, String area) {
this.name = name;
this.area = area;
}
public void addanimal(animal ann) {
animals.add(id, ann);
id++;
}
}
public class Animal {
String name;
String type;
String age;
String gender;
public Animal(String name, String type, String age, String gender) {
this.name = name;
this.type = type;
this.age = age;
this.gender = gender;
}
}
public class Test {
public static void main(String[] args) {
Zoo nozha = new Zoo("nozha", "100");
Animal lion = new Animal("lion", "male", "20", "fine");
nozha.addanimal(lion);
Znimal tiger = new Animal("tiger", "male", "30", "ssc");
nozha.addanimal(tiger);
System.out.print(Zoo.id);
}
}
First I need help with function (addanimal) because when I print (zoo.id) its not working and I didn't know how to remove animal please help me i am beginner in programming and this is my first time i used ArrayList and I never asked before
Zoo,Animal), method names use camel case (addAnimal).2assuming you changedList<Animal> animals = new ArrayList<Animal>();idshould certainly not be static.