Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new Java project in Eclipse, named according to the lab guidelines (mandatory guidelines of laboratories - available on the blackboard). For this lab,

Create a new Java project in Eclipse, named according to the lab guidelines (mandatory guidelines of laboratories - available on the blackboard). For this lab, you may reuse your code from Lab 1, but you should correct any mistakes. If you copy the files over, ensure that you choose "copy" if prompted, rather than "link", as the latter will not move the file into this project directory. Your project should now contain Zoo.java, Zone.java, and Animal.java. All classes in this lab will be in the default package of your project. Your application will read in data from text files placed in an animalData directory. Sample files (animals.csv and zones.csv) can be downloaded from the blackboard. Unzip it and place the folder with files at the top of your project in Eclipse. Note: the top of your project is within the folder for the project, not within the src folder. To get you started, there is a test class provided, Lab2.java. Your final submission must include this class exactly as it appears, and the data files given. The only permitted modification to this code is to add Javadoc comments as needed. Once your application is completed, running Lab2.java with the given data files will result in the exact output shown in the attached PDF file. Carefully inspect the output and modify your toString() methods accordingly.

Animal.java

Animal objects will be as previously defined in Lab 1, additionally they will have:

A zone code (i.e. T for the Tiger zone)

All class variables must have getters and setters

Zone.java

With addition to previous definition of Zone objects they will have:

An ArrayList of Animal objects (you can discard previous Array!)

A zone code (i.e. T for the Tiger zone) in addition to the existing zone name.

A required safety rating (i.e. low, medium, high, critical) This class should have a method addAnimal which takes in an Animal and adds them to that respective Zone. It should also have a method removeAnimal which takes in an Animal and removes them from that Zone.

All class variables must have getters and setters.

Zoo.java

The Zoo class will be as previously defined; however it will also contain an ArrayList of Zone objects, rather than an array. In order to work with the code provided in Lab2.java, this class will need two new methods: loadZones(..) and loadAnimals(..). Both methods will take in a file name and throw an IOException. These object methods will load the data in the given file into the appropriate objects (zones are added to the zoo, and animals are added to respective zones). Create an object method relocate(..) which takes as parameters the name of an animal and the zone code to which they should be relocated. This method should remove the animal from their currently assigned zone, and add them to the zone given by the zone code parameter. Create an object method save() which takes no parameters and saves all current information of the zoo back into the data files provided. This way, if any animals have been relocated, their new zone information will appear with their name in the zoo files. Be sure to overwrite the data in the file, rather than append to it. The data must be saved in the same format as provided in the CSV files. All class variables must have getters and setters.

OUTPUT

image text in transcribed

Animal.java

public class Animal { private String Name; private String Type; private boolean Diet; public Animal(String Name, String Type, boolean Diet) { this.Name = Name; this.Type = Type; this.Diet = Diet; } public Animal() { Name = ""; Type=""; Diet = false; } public String getAnimalName() { return this.Name; } public void setAnimalName(String Name) { this.Name = Name; } public String getAnimalType() { return this.Type; } public void setAnimalType(String Type) { this.Type = Type; } public boolean Diet() { return Diet; } public void setDiet(boolean Diet) { this.Diet = Diet; } public String toString() { return ">>" + Name + " - " + Type + " " + (!Diet ? "(Vegetarian)" : "(Carnivore)"); } }

Zone.java

public class Zone {

private String zoneName; private Animal animal[]; private int count; public Zone(String zoneName, int count) { this.zoneName = zoneName; animal = new Animal[100]; count = 0; } public void addAnimal (Animal animals) { if (count

Zoo.java

public class Zoo { private String zooName; private Zone zones[]; private int zoneCount; public Zoo(String zooName, int zoneCount) { this.zooName=zooName; zones = new Zone[100]; zoneCount = 0; } public void addZone(Zone x) { if(zoneCount

for (int i=0; i

Lab2.java

public class Lab2 {

public static void main( String[] args ) throws IOException { Zoo animalKingdom = new Zoo( "Animal Kingdom" ); // Load data for the zoo, and print its current status animalKingdom.loadZones("animalData/zones.csv"); animalKingdom.loadAnimals("animalData/animals.csv"); System.out.println( animalKingdom ); // Relocate the lion, "Christian" to the "Lion" zone, it was kept //in the "Tiger" zone! then print updated status of the Zoo. animalKingdom.relocate( "Christian", "L" ); animalKingdom.save(); System.out.println( animalKingdom ); } }

Animals.csv

image text in transcribed

zones.csv

image text in transcribed

Welcome to Animal Kingdom! ============================= M: Monkey Zone (low risk): ------ ---------------------- >> Bubbles The Chimp - Monkey (vegetarian) >> Grape Ape - Monkey (vegetarian) T: Tiger Zone (high risk): ---- ----------- >> Shere Khan - Tiger (carnivore) >> Trigger - Tiger (carnivore) >> Christian - Lion (carnivore) L: Lion Zone (high risk): ----- -------- >> Aslan - Lion (carnivore) >> Simba - Lion (carnivore) E: Elephant Zone (medium risk): ----- >> Elmar - Elephant (vegetarian) Welcome to Animal Kingdom! ====== ======================= M: Monkey Zone (low risk): ----- >> Bubbles The Chimp - Monkey (vegetarian) >> Grape Ape - Monkey (vegetarian) T: Tiger Zone (high risk): ------ >> Shere Khan - Tiger (carnivore) >> Trigger - Tiger (carnivore) ------ ------ L: Lion Zone (high risk): ------------ >> Aslan - Lion (carnivore) >> Simba - Lion (carnivore) >> Christian - Lion (carnivore) E: Elephant Zone (medium risk): ----- >> Elmar - Elephant (vegetarian) D I AB I 1 Bubbles Th| Monkey 2 Grape Ape Monkey 3 Shere Khan Tiger 4 Trigger Tiger 5 Aslan Lion 6 Simba Lion 7 Christian Lion 8 Elmar Elephant C FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE M M. T I L L I E M Monkey llow Tiger high Lion high Elephant medium L E

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions