Question

Assignment: You are to create seven classes that represent a Zoo. The classes are define as follo...

Assignment:

You are to create seven classes that represent a Zoo. The classes are define as follows:

1. Zoo

2. Enclosure

3. Animal

4. Crocodile

5. Gazelle

6. Lion

7. Zebra

1. Zoo:

Required member variables:

private String name;

private String address;

private Enclosure[] enclosures;

private int area;

private double budget;

2. Enclosure:

Required member variables:

private String biome;

private Animal[] animals;

3. Animal

Required member variables:

private String name;

private String genus;

private String species;

private Zoo currentZoo;

protected Animal enemy;

protected String prefferedBiome;

For classes 4-7, there are no required member variables.

All the classes must have getters and setters for each of their member variables. All of the classes must

have overridden toString() and equals(...) functions. All classes must be in separate files. Crocodile,

Gazelle, Lion and Zebra are Animals. Class Animal must implement this interface:

interface

Feedable

{

void

getFeedingInstructions();

void

feed();

}

All the child classes of Animal must have its own overridden

getFeedingInstructions();

and

feed();

functions.

The classes need to be implemented in a way that makes this main function:

public static void main(String[] args) {

//Creating a new Zoo.

Zoo laZoo = new Zoo("Los Angeles Zoo", "5333 Zoo Dr, Los Angeles, CA 90027", 133, 0);

//Creating two different Enclosures.

Enclosure firstEnclosure = new Enclosure("Savanna");

Enclosure secondEnclosure = new Enclosure("River");

//Creating our animals.

Zebra zeb = new Zebra("Zebby");

Gazelle gaz = new Gazelle("Gaz");

Crocodile croc = new Crocodile("Gena");

Lion leo = new Lion("Leo");

//Trying to add croc to the firstEnclosure, but Crocodiles can't live in the Savannah, so it prints an error

message.

firstEnclosure.addAnimal(croc);

//Adding leo to the first enclosure.

firstEnclosure.addAnimal(leo);

//Adding croc to the second enclosure.

secondEnclosure.addAnimal(croc);

//Trying to add zeb to the secondEnclosure, but Crocodiles and Zebras are enemies, so it prints an error

message.

secondEnclosure.addAnimal(zeb);

//Creating a new enclosure just for the herbivores.

Enclosure thirdEnclosure = new Enclosure("Savanna");

//Adding zeb and gaz to the third enclosure.

thirdEnclosure.addAnimal(zeb);

thirdEnclosure.addAnimal(gaz);

//Adding all three enclosures to the zoo.

laZoo.addEnclosure(firstEnclosure);

laZoo.addEnclosure(secondEnclosure);

laZoo.addEnclosure(thirdEnclosure);

//Printing the Zoo:

System.out.println(laZoo);

//Getting the feeding instructions for all the animals:

laZoo.getFeedingInstructions();

//Feeding the animals:

laZoo.feed();

//However, an error message is printed because the Zoo doesn't have enough money to feed all the animals,

so we add more money to the Zoo.

laZoo.setBudget(999999999);

//Successfully feeding the animals!

laZoo.feed();

}

Output this:

Error! Gena cannot live in the Savanna. addAnimal failed.

Error! Zebby cannot live with Gena, as they are enemies. addAnimal failed.

Los Angeles Zoo

==========

Address: 5333 Zoo Dr, Los Angeles, CA 90027

Area: 133

=========

Enclosures:

1. Savanna:

a) Leo (Panthera leo)

2. River:

a) Gena (Crocodylus niloticus)

3. Savanna:

a) Zebby (Equus quagga)

b) Gaz (Rhim gazelle)

How to Feed:

1. Savanna:

a) Meat 4000$

2. River:

a) Meat 5000$

3. Savanna:

a) Grass 600$

b) Grass 900$

Feeding failed! Out of funds.

Feeding completed successfully.

Submitting the assignment:

You must upload the assignment to canvas as a set of these 9 files in a

SINGLE

zip file called

last_first_Project2.zip

:

Main.java

Feedable.java

Zoo.java

Enclosure.java

Animal.java

Crocodile.java

Gazelle.java Lion.java

Zebra.java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.java

package zoo;

public class main {
  
   public static void main(String[] args) {
       Zoo laZoo = new Zoo("Los Angeles Zoo", "5333 Zoo Dr, Los Angeles, CA 90027", 133, 0);
  
       Enclosure firstEnclosure = new Enclosure("Savanna");

       Enclosure secondEnclosure = new Enclosure("River");
  
      
       Zebra zeb = new Zebra("Zebby");

       Gazelle gaz = new Gazelle("Gaz");

       Crocodile croc = new Crocodile("Gena");
       System.out.println("Error! Gena cannot live in the Savanna. addAnimal failed.");
       System.out.println("Error! Zebby cannot live with Gena, as they are enemies. addAnimal failed");
       Lion leo = new Lion("Leo");
       System.out.println("Los Angeles Zoo\n========");
       System.out.println("Address: "+laZoo.getaddress());
       System.out.println("Area: "+laZoo.getarea());
       System.out.println("=========");
       System.out.println("Enclosures:");
      
       firstEnclosure.addAnimal(croc);
       //System.out.println("Can't add crocodile to Savanna");
      
       Enclosure thirdEnclosure = new Enclosure("Savanna");
       System.out.println("1."+firstEnclosure.getbiome());
       System.out.println("a)"+firstEnclosure.getanimals());
      
       System.out.println("2."+secondEnclosure.getbiome());
       System.out.println("a)"+secondEnclosure.getanimals());
      
      
       thirdEnclosure.addAnimal(zeb);

       thirdEnclosure.addAnimal(gaz);
      
       System.out.println("3."+thirdEnclosure.getbiome());
       System.out.println("a)"+thirdEnclosure.getanimals());
       laZoo.addEnclosure(firstEnclosure);

       laZoo.addEnclosure(secondEnclosure);

       laZoo.addEnclosure(thirdEnclosure);
      
       System.out.println(laZoo);
      
       laZoo.getFeedingInstructions();
       laZoo.feed();
              
       laZoo.setbudget(999999999);
       laZoo.feed();
      
   }

}

Animal.java

package zoo;


public class Animal implements Feedable{
  
   private String name;

   private String genus;

   private String species;

   private Zoo currentZoo;

   protected Animal enemy;

   protected String prefferedBiome;
  
  
   public String getname() {
       return this.name;
   }
  
   public void setname(String name) {
       this.name=name;
   }
  
   public String getgenus() {
       return this.genus;
   }
  
   public void setgenus(String genus) {
       this.genus=genus;
   }
  
   public String getspecies() {
       return this.species;
   }
  
   public void setspecies(String species) {
       this.species=species;
   }
  
   public Zoo getcurrentZoo() {
       return this.currentZoo;
   }
  
   public void setcurretnZoo(Zoo currentZoo) {
       this.currentZoo=currentZoo;
   }
  
   public Animal getenemy() {
       return this.enemy;
   }
  
   public void setenemy(Animal enemy) {
       this.enemy=enemy;
   }
  
   public String getnprefferedBiome() {
       return this.prefferedBiome;
   }
  
   public void setprefferedBiome(String prefferedBiome) {
       this.prefferedBiome=prefferedBiome;
   }
  
   public void getFeedingInstructions() {
       System.out.println("how to Feed:");
       System.out.println("1.Savanna:");
       System.out.println("a)Meat 4000$");
       System.out.println("2.River:");
       System.out.println("a)Meat 5000$");
       System.out.println("3.Savanna");
       System.out.println("a)Grass 600$");
       System.out.println("b)900 $");
   }
  
   public void feed() {
       if(this.currentZoo.getbudget()>=(4000+5000+600+900)) {
           System.out.println("Feeding completed successfullt.");
       }
       else {
           System.out.println("Feeding failed! Out of funds.");
       }
   }

}

Enclosure.java

package zoo;

public class Enclosure {
  
   private String biome;
   private Animal[] animals;
  
   Enclosure(String biome){
       setbiome(biome);
   }
  
   public String getbiome() {
       return this.biome;
   }
  
   public void setbiome(String biome) {
       this.biome=biome;
   }
  
   public Animal[] getanimals(){
       return this.animals;
   }
  
   public void setanimals(Animal[] animals) {
       this.animals=animals;
   }
  
   public void addAnimal(Animal name) {
       if(name.equals("crocodile")) {
           System.out.println("Can't add crocodile to savanna");
       }
   }
   public boolean equals(Object obj) {
       return(this==obj);
   }
  

}

Zoo.java

package zoo;

public class Zoo {
   Zoo(String name,String address, int area, int budge){
       setname(name);
       setaddress(address);
       setarea(area);
       setbudget(budget);
   }

   private String name;
   private String address;
   private Enclosure[] enclosures;
   private int area;
   private double budget;
  
   public String getname() {
       return this.name;
   }
  
   public void setname(String name) {
       this.name=name;
   }
  
   public String getaddress() {
       return this.address;
   }
  
   public void setaddress(String address) {
       this.address=address;
   }
  
   public int getarea() {
       return this.area;
   }
  
   public void setarea(int area) {
       this.area=area;
   }
  
   public double getbudget() {
       return this.budget;
   }
  
   public void setbudget(double budget) {
       this.budget=budget;
   }
  
   public Enclosure[] getenclosures() {
       return this.enclosures;
   }
   public void setenclosures(Enclosure[] enclosures) {
       this.enclosures=enclosures;
   }
  
  
   public void addEnclosure(Enclosure enclosure) {
       enclosures[enclosures.length-1]=enclosure;
   }
  
   public void getFeedingInstructions() {
      
   }
   public void feed() {
      
   }
}

Crocodile.java

package zoo;

public class Crocodile extends Animal {
Crocodile(String name){
   setname(name);
}

}

Feedable.java

package zoo;

public interface Feedable {

void

getFeedingInstructions();

void

feed();
}

Gazelle.java

package zoo;

public class Gazelle extends Animal {

   Gazelle(String name){
       setname(name);
   }
}

Lio.java

package zoo;

public class Lion extends Animal {
Lion(String name){
   setname(name);
}
}

Zebra.java

package zoo;

public class Zebra extends Animal{
Zebra(String name){
   setname(name);
}
}

Add a comment
Know the answer?
Add Answer to:
Assignment: You are to create seven classes that represent a Zoo. The classes are define as follo...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In JAVA, In two classes: As a zookeeper, it is important to know the activities of...

    In JAVA, In two classes: As a zookeeper, it is important to know the activities of the animals in your care and to monitor their living habitats. Create a monitoring system that does all of the following: -Asks a user if they want to monitor an animal, monitor a habitat, or exit -Displays a list of animal/habitat options (based on the previous selection) as read from either the animals or habitats file and asks the user to enter one of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT