Answered step by step
Verified Expert Solution
Question
1 Approved Answer
List Part A [7 marks]: Suppose you are working for a Zoo and you are asked to write the class for keeping information about animals.
List Part A [7 marks]: Suppose you are working for a Zoo and you are asked to write the class for keeping information about animals. You decide to call your class as Animal. Write a class to represent a Animal. The attributes are: the animal id, the species, price, and a flag indicating whether it is currently being in a show. o Note that, when an animal is created, a unique new id number is allocated to id. This id number will be generated by adding one to the previously used id number, which is kept stored in a variable shared by all Animal objects. Include accessors for all attributes, a mutator to change the flag, and a method to increase the price. Two most necessary constructors (that will be used create new animal(s)); Part B [14 marks]: Given a class named AnimalDatabase, which will be used to provide the responsibility of data management of a set of Animal objects. Internally, it should use an ArrayList of Animal as follows: Public class AnimalDatabase{ private ArrayList animalList = new ArrayList(); You should provide: implementation for a method to add a not null animal object into the animalList. [1 mark] o public void add(Animal a){........} implementation for a method to report the average price of the animals. Assume that there is a method getPrice() in Class Animal. [2 marks] o public double getAveragePrice(){....} . implementation for a method to retrieve a specific animal by id. Assume that there is a method getld() in Class Animal. [2 marks] o public Animal getAnimalById(int id){...} implementation for a safe way method to obtain an ArrayList of all the animals within a given range of prices. [2 marks] o public ArrayListgetAnimalsInRange(double minPrice, double maxPrice); implementation for a method called reportAnimlas () which should write the animal objects stored in the animalList to a text file named "animals- report.txt". You should use the printf() method to format your data in the following structure: [7 marks] o public void reportAnimlas (); ID Show 100 Species Price Cat $100.0 Dog $120.0 true 101 false Part C [7 marks]: There is a text file containing the details of several animal details. Each animal uses 3 lines of the file. The first of the three lines is a string giving the species of the animal, for example "Dog" or "Cat". The second of the three lines contains double giving the price, the third line is boolean indicating whether it is currently being in a show. However, the very first line of the file is an integer number, which says how many animals are iven in the file in the lines which follow it (i.e. how many records will follow). Text file example for two animals "animals.txt" Part C [7 marks]: There is a text file containing the details of several animal details. Each animal uses 3 lines of the file. The first of the three lines is a string giving the species of the animal, for example "Dog" or "Cat". The second of the three lines contains double giving the price, the third line is boolean indicating whether it is currently being in a show. However, the very first line of the file is an integer number, which says how many animals are given in the file in the lines which follow it (i.e. how many records will follow). Text file example for two animals "animals.txt" 2 Cat 100.0 true Dog 120.0 false Write code for a method named processTextFile() which will open the file named 'animals.txt', from which it will read the data of animals. will create Animal objects using this data by calling the constructor that takes the parameters (species, price, show), placing them into an ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started