Lab Task 010
Lab Task 010
Question 01:
import java.util.ArrayList;
class Animal {
String name, species;
int age;
Enclosure currentEnclosure;
void displayInfo() {
System.out.println("Animal: " + name + ", Species: " + species + ", Age: " + age + ", Enclosure: " + (currentEnclosure !=
null ? currentEnclosure.enclosureNumber : "None"));
}
}
class Enclosure {
int enclosureNumber;
String size, type;
ArrayList<Animal> animals = new ArrayList<>();
void displayEnclosureInfo() {
System.out.println("Enclosure " + enclosureNumber + " (" + type + ", " + size + ")");
System.out.println("Animals Inside:");
for (Animal a : animals) {
System.out.println(" - " + a.name + " (" + a.species + ")");
}
}
}
class Zoo {
ArrayList<Animal> animals = new ArrayList<>();
ArrayList<Enclosure> enclosures = new ArrayList<>();
void displayAllAnimals() {
System.out.println("All Animals in the Zoo:");
for (Animal a : animals) {
a.displayInfo();
}
}
void displayAllEnclosures() {
System.out.println("All Enclosures:");
for (Enclosure e : enclosures) {
e.displayEnclosureInfo();
}
}
}
class Course {
String courseID;
String courseName;
int credits;
School() {
students = new ArrayList<>();
courses = new ArrayList<>();
}