Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I was sick for the past 2 weeks and I am now a little behind on school work. I am trying to catch up,

Hello, I was sick for the past 2 weeks and I am now a little behind on school work. I am trying to catch up, however I am struggling with this programming exercise. It is a task that consists of 2 different parts.

I would really appreciate it if somebody could help me it. Thanks in advance!

image text in transcribedimage text in transcribed

Task 2 Task 2.1 Requirement Write a Class Animal, that contains Data members: Oname o gender o age o type o a static ArrayList that holds all legal types Originally only contains "Cat", "Dog" and "Monkey", but the list can be expended or shortened in the future. Methods: o Default constructor o Constructor with all data members o Copy constructor o boolean isTypeValid (String type) o equals() o toString() Example Name : Copain Gender : Male Age : 5 Type : Dog o getters and setters You should use isTypeValid() in setType() and constructor(s) Task 2.2 Requirement Write a Class Zoo, that contains Data members: o animals a collection of animals, the number is NOT FIXED, you can add a new animal or remove one from it. . Methods: : Default constructor o Constructor with all data members o Copy constructor o int countAnimals(String type) count in the zoo, how many animals belong to a certain type o void updateValidTypes() go through all animals in the zoo and check if there is a valid type in the ArrayList from which no animals in the zoo belong to that type. If so, remove the type from the valid type ArrayList. o boolean isGenderBalanced(String type) check if, for a specific type, the difference between the number of female and number of male is less than 20% of the total number of animals of that type. o void removeOldest(String type) first check if the type is valid or not, if it is valid, then remove the oldest animal(s) of a certain type from the animals (if two animals have the same age, remove both), it calls updateValidTypes() in the end. o equals() o toString() Example: Total Number of Animals: 28 Male: 12 Female: 16 Dog: Number : 6 Female : 3 Male : 3 Balanced : Yes Oldest age: 12 Cat: Number : 9 Female : 7 Male : 2 Balanced : No Oldest age: 7 Monkey: Number : 13 Female : 6 Male Balanced : No Oldest age: 20 o getters and setters

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago

Question

Was there an effort to involve the appropriate people?

Answered: 1 week ago