Dubai Zoo is asking you to write a Java program that manages the animals in the
ID: 3712810 • Letter: D
Question
Dubai Zoo is asking you to write a Java program that manages the animals in the zoo. Animals are distributed over 5 sections. The user of your program should be able to add an animal, delete an animal, modify an animal, list all animals in a specific section, list all animals from a specific specie, and print all animals (from all species). Data on all animals should be stored in files. A menu asks the user which operation he wants to perform. Guidelines: Please observe the following guidelines while writing your programs: • Use appropriate names of classes, variables, and methods. • Make good and appropriate use of inheritance (at least one) • Make good and appropriate use of abstract classes (at least one) • Make good and appropriate use of polymorphism (at least one) • Provide enough comments to understand your code • Use appropriate indentations
Explanation / Answer
public class Zoo
{
private String[] animals;
private String city;
public Zoo()
{}
public Zoo(String[] a, String c)
{
animals = new String[a.length];
for (int i=0; i<a.length; i++)
{
animals[i] = a[i];
}
city = c;
}
public void display()
{
String zooContent;
if (city == null || animals == null)
{
System.out.println("The zoo is vacant");
}
else
{
zooContent = city + " zoo:";
zooContent += " " + animals[0];
for (int i=1; i<animals.length; i++)
{
zooContent += ", " + animals[i];
}
System.out.println(zooContent);
}
} // end display
//*********************************************
public static void main(String[] args)
{
Zoo zoo1 = new Zoo();
String[] animals = {"pig", "possum", "squirrel", "Chihuahua"};
Zoo zoo2 = new Zoo(animals, "Parkville");
animals[0] = "white tiger";
Zoo zoo3 = new Zoo(animals, "San Diego");
zoo1.display();
zoo2.display();
zoo3.display();
} // end main
} // end class Zoo
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.