Question: Java Coding Assignment using Eclipse Contains outline of he code Write code to make zoo that contains only elephants and kangaroos.It's a special limited kind

Java Coding Assignment using Eclipse

Contains outline of he code

Write code to make zoo that contains only elephants and kangaroos.It's a special limited kind of zoo!

What's allowed:

Use regular arrays to solve this problem.

Use the classes I've provided (see code below).

Use the elephants and kangaroos I've provided in main (see code below).

What's not allowed:

Do not hardcode.The code must work for ANY number of elephants and ANY number of kangaroos. The elephants and kangaroos I've provided are only an example.

Do not change the parameters on the methods in the zoo class.

Do not use ArrayLists.

What is provided (see code below):

Severalelephant and kangaroo objects have already been created in main and placed into an array.

Complete code for the following classes is also provided:

oZooAnimal

oElephant

oKangaroo

What you must do:

Step 1: Write the code for the Zoo class as specified below.

Zoo Class

Description: class that represents a limited zoo for elephants and kangaroos

Private Data Fields (must be defined as private!)

onumElephants- int

onumKangaroos - int

ozooAnimals - array of ZooAnimals

Public Methods

oConstructor: none

oGetters - none

oSetters - none

oPublic methods.

public void fillZoo(ZooAnimal[] animals)

oAllocate memory for zooAnimals array based on number of animals coming in

oFills the zooAnimals array with the animals that are sent in.

oKeep track of how many elephants and kangaroos are added to the zoo.

oEnsure the animals are removed from the incoming array.This means, when the code returns to main the animals array must contain no objects (all slots are null).

public void printZooDetails()

oDisplays the number of elephants and kangaroos

oDisplays the name and location of each animal in the zoo.

Step 2: Write code in main to:

oMake zoo object

oFill the zoo with the provided elephants and kangaroos (call fillZoo method on the Zoo object)

oPrint the zoo details (call printZooDetails on the Zoo object)

Output:

The output for the example elephants and kangaroos I've provided is:

Number elephants: 2

Number kangaroos: 3

Zoo Animals

------------------------------

Jumbo is in Enclosure 23

Thumper is in Enclosure 17

Titan is in Enclosure 23

Jack is in Enclosure 17

Sheila is in Enclosure 17

Animals [0] is empty

Animals [1] is empty

Animals [2] is empty

Animals [3] is empty

Animals [4] is empty

Getting Started:

Step 1: Make java file using option #1 or #2:

oOption #1: Cut and paste the code shown below into a new Java class you create.

oOption #2: Import the provided .java file and add your solution to the provided code.

oNote: Your file must use our standard naming convention: LastNameFirstNameFinal

oWith either option, be sure to change the name of the class to your first and last name.

oTo rename a file in Eclipse, right click on the file in Eclipse, then select Refactor then Rename.

Step 2: Start coding

Add your solution to this code.

Don't forget to change this name

public class LastNameFirstNameFinal {

public static void main(String[] args) {

// These are the elephants and kangaroos to be placed into the zoo

Elephant elephant1 = new Elephant("Jumbo", "Enclosure 23");

Elephant elephant2 = new Elephant("Titan", "Enclosure 23");

Kangaroo kangaroo1 = new Kangaroo("Thumper", "Enclosure 17");

Kangaroo kangaroo2 = new Kangaroo("Jack", "Enclosure 17");

Kangaroo kangaroo3 = new Kangaroo("Sheila", "Enclosure 17");

// Array to hold Animal objects that will be placed into the zoo

ZooAnimal[] animals = new ZooAnimal[5];

animals[0] = elephant1;

animals[1] = kangaroo1;

animals[2] = elephant2;

animals[3] = kangaroo2;

animals[4] = kangaroo3;

//**** STEP 2: ADD SOLUTION FOR MAIN HERE AFTER YOU COMPLETE THE ZOO CLASS BELOW *****

//Make zoo, fill the zoo with the animals, print the animals in the zoo

// After you make and fill the zoo with animals this code proves that there

// are no animals left in the animals array.If you see the output "Issue!..."

// it means the animals array is not empty.

System.out.println();

for (int i = 0; i < animals.length; i++) {

if (animals[i] == null) {

System.out.println("Animals [" + i + "] is empty");

}

else {

System.out.println("Issue! Array still contains animal at index " + i);

}

}

} // main

} // CS 1150 Final

//***********************************

// Zoo Class

//***********************************

class Zoo {

// STEP 1: finish class

} // zoo

//**************************************************

// Given classes - ZooAnimal, Elephant, Kangaroo

//**************************************************

class ZooAnimal {

private String name;

private String location;

public ZooAnimal(String name, String location) {

this.name = name;

this.location = location;

}

public String getName() {

return name;

}

public String getLocation() {

return location;

}

} // ZooAnimal

class Elephant extends ZooAnimal {

public Elephant(String name, String location) {

super(name, location);

}

} // Elephant

class Kangaroo extends ZooAnimal {

public Kangaroo(String name, String location) {

super(name, location);

}

} // Kangaroo

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!