Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Progaming Question We will be creating a virtual Zoo. Just like a real Zoo,

ID: 3709020 • Letter: J

Question

Java Progaming Question

We will be creating a virtual Zoo. Just like a real Zoo, ours will have a name and will be made up of Exhibits that people will come to see their favorite animals at. Our virtual Zoo will have four (4) Exhibits:

Aquatic

Bear

Reptile

Bird

Each exhibit has a name and for our case, will have two different animals in each exhibit. To keep things simple for us, our Animals at our Zoo will only have a name and a voice. A voice will be a text representation of what noise they make (e.g. the voice of a Pig would be “Oink”).

Create a new project and name it “Zoo”

Our Zoo project will have 4 Classes in it (25 pts each)

Animal - This will be our class to represent an Animal. This will be the same class that you created in Homework 5.

Exhibit - This will be our class to represent an exhibit at our Zoo (like a dolphin show or something). Our Exhibit will have a name and two (2) animals associated with it

Zoo - This will be our class to represent our Zoo. Our Zoo will have a name and four (4) Exhibits (feel free to make more than that if you want!).

Driver - This will be our class with our main() method to create our Zoo and set everything up.

Create a new instance of your Zoo object.

You will need to create Create four (4) exhibits to make our Zoo (aquatic, bear, reptile, and bird).

You will need to create and add two (2) animals to each exhibit. Have fun with which animals you put in which exhibit and what their “voice” is if you want (aka the animals don’t have to make perfect sense for the exhibit you add them to) but do make sure that you do not just use the same animals for every exhibit.

Once you have your Zoo object fully populated, call the visitAllExhibits() method.

Use the given UML Diagrams to create your classes:

Animal

-

-

name : String

voice : String

+

+

+

+

+

+

+

Animal ( )

Animal ( name : String, voice : String )

getName ( ) : String

setName ( name : String ) : void

getVoice ( ) : String

setVoice ( voice : String ) : void

talk ( ) : String

Talk will return the result of the name of the animal and the voice field.

e.g. “{name of the animal} says ‘{voice}’ ”

Exhibit

-

-

-

exhibitName : String

firstAnimal : Animal

secondAnimal : Animal

+

+

+

Exhibit ( )

Exhibit ( name : String, firstAnimal : Animal, secondAnimal : Animal)

startExhibit() : void

The startExhibit method will need to write 2 lines out to the console:

·       “The {name of exhibit} exhibit is now starting…”, where {name of exhibit} will be the name assigned to the Class variable name

·       Call the talk() method on the firstAnimal and then concatenate a space (“ “) and then concatenate the value returned from calling the talk() method on the secondAnimal

Generate getters and setters for all of the instance variables.

Zoo

-

-

-

-

-

zooName : String

aquaticExhibit : Exhibit

bearExhibit : Exhibit

reptileExhibit : Exhibit

birdExhibit : Exhibit

+

+

+

Zoo ( )

Zoo( zooName : String )

visitAllExhibits ( ) : void

The visitAllExhibits method will call all 4 exhibits that make up our Zoo and will call the startExhibit() method on each one.

Feel free to create an additional constructor that takes all your instance variables if you want for your own testing purposes, just make sure that you have the 2 that are required.

Animal

-

-

name : String

voice : String

+

+

+

+

+

+

+

Animal ( )

Animal ( name : String, voice : String )

getName ( ) : String

setName ( name : String ) : void

getVoice ( ) : String

setVoice ( voice : String ) : void

talk ( ) : String

Talk will return the result of the name of the animal and the voice field.

e.g. “{name of the animal} says ‘{voice}’ ”

Explanation / Answer

Hello. Here is the required code you asked. Created Animal, Zoo, Exhibit and Driver classes as mentioned, and explained using comments. Go through it and let me know if you have any doubts. Thanks.

// Animal.java

public class Animal {

                //attributes

                private String name;

                private String voice;

                /**

                * default constructor

                */

                public Animal() {

                                name="";

                                voice="";

                }

                /**

                * constructor with arguments to initialize all fields

                */

                public Animal(String name, String voice) {

                                super();

                                this.name = name;

                                this.voice = voice;

                }

               

                //getters and setters

               

                public String getName() {

                                return name;

                }

                public void setName(String name) {

                                this.name = name;

                }

                public String getVoice() {

                                return voice;

                }

                public void setVoice(String voice) {

                                this.voice = voice;

                }

                /**

                * returns a String containing animal name and their voice

                */

                public String talk(){

                                return name+" says "+voice;

                }

}

// Exhibit.java

public class Exhibit {

                //attributes

                private String exhibitName;

                private Animal firstAnimal;

                private Animal secondAnimal;

                /**

                * default constructor

                */

                public Exhibit() {

                                exhibitName="";

                                firstAnimal=null;

                                secondAnimal=null;

                }

                /**

                * constructor with arguments to initialize all fields

                */

                public Exhibit(String exhibitName, Animal firstAnimal, Animal secondAnimal) {

                                this.exhibitName = exhibitName;

                                this.firstAnimal = firstAnimal;

                                this.secondAnimal = secondAnimal;

                }

                /**

                * method to start exhibition

                */

                public void startExhibit(){

                                System.out.println("The "+exhibitName+" is now starting...");

                                System.out.println(firstAnimal.talk()+" "+secondAnimal.talk());

                }

                //getters and setters

               

                public String getExhibitName() {

                                return exhibitName;

                }

                public void setExhibitName(String exhibitName) {

                                this.exhibitName = exhibitName;

                }

                public Animal getFirstAnimal() {

                                return firstAnimal;

                }

                public void setFirstAnimal(Animal firstAnimal) {

                                this.firstAnimal = firstAnimal;

                }

                public Animal getSecondAnimal() {

                                return secondAnimal;

                }

                public void setSecondAnimal(Animal secondAnimal) {

                                this.secondAnimal = secondAnimal;

                }

               

               

}

//Zoo.java

public class Zoo {

                //attributes

                private String zooName;

                private Exhibit aquaticExhibit;

                private Exhibit bearExhibit;

                private Exhibit reptileExhibit;

                private Exhibit birdExhibit;

                /**

                * default constructor

                */

                public Zoo() {

                                zooName="";

                                aquaticExhibit=null;

                                bearExhibit=null;

                                reptileExhibit=null;

                                birdExhibit=null;

                }

                /**

                * constructor with argument to initialize zoo name

                */

                public Zoo(String zooName){

                                this.zooName=zooName;

                                aquaticExhibit=null;

                                bearExhibit=null;

                                reptileExhibit=null;

                                birdExhibit=null;

                }

                //getters and setters

               

                public String getZooName() {

                                return zooName;

                }

                public void setZooName(String zooName) {

                                this.zooName = zooName;

                }

                public Exhibit getAquaticExhibit() {

                                return aquaticExhibit;

                }

                public void setAquaticExhibit(Exhibit aquaticExhibit) {

                                this.aquaticExhibit = aquaticExhibit;

                }

                public Exhibit getBearExhibit() {

                                return bearExhibit;

                }

                public void setBearExhibit(Exhibit bearExhibit) {

                                this.bearExhibit = bearExhibit;

                }

                public Exhibit getReptileExhibit() {

                                return reptileExhibit;

                }

                public void setReptileExhibit(Exhibit reptileExhibit) {

                                this.reptileExhibit = reptileExhibit;

                }

                public Exhibit getBirdExhibit() {

                                return birdExhibit;

                }

                public void setBirdExhibit(Exhibit birdExhibit) {

                                this.birdExhibit = birdExhibit;

                }

                /**

                * method to start exhibition of all exhibits

                */

                public void visitAllExhibits(){

                                aquaticExhibit.startExhibit();

                                bearExhibit.startExhibit();

                                reptileExhibit.startExhibit();

                                birdExhibit.startExhibit();

                }

               

}

//Driver.java

public class Driver {

                public static void main(String[] args) {

                                /**

                                * Defining 8 animals in different categories

                                */

                                Animal a1=new Animal("Dolphin", "cleeek");

                                Animal a2=new Animal("Frog", "croak");

                               

                                Animal a3=new Animal("Bear", "roar");

                                Animal a4=new Animal("Wolverine", "growl");

                               

                                Animal a5=new Animal("King kobra", "hiss");

                                Animal a6=new Animal("Rattle snake", "shisssss");

                               

                                Animal a7=new Animal("Duck", "quack");

                                Animal a8=new Animal("Crow", "kraaa");

                                /**

                                * Defining all the four exhibits

                                */

                                Exhibit aquaticExhibit=new Exhibit("Aquatic Exhibit", a1, a2);

                                Exhibit bearExhibit=new Exhibit("Bears Exhibit", a3, a4);

                                Exhibit reptileExhibit=new Exhibit("Reptiles Exhibit", a5, a6);

                                Exhibit birdExhibit=new Exhibit("Birds Exhibit", a7, a8);

                                /**

                                * Defining a Zoo and setting all required exhibits

                                */

                                Zoo zoo=new Zoo("Freeworld Zoo");

                                zoo.setAquaticExhibit(aquaticExhibit);

                                zoo.setBearExhibit(bearExhibit);

                                zoo.setBirdExhibit(birdExhibit);

                                zoo.setReptileExhibit(reptileExhibit);

                                /**

                                * visiting all exhibits

                                */

                                zoo.visitAllExhibits();

                }

}

//OUTPUT

The Aquatic Exhibit is now starting...

Dolphin says cleeek Frog says croak

The Bears Exhibit is now starting...

Bear says roar Wolverine says growl

The Reptiles Exhibit is now starting...

King kobra says hiss Rattle snake says shisssss

The Birds Exhibit is now starting...

Duck says quack Crow says kraaa

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote