Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this program please! ANIMAL CLASS: import java.util.Calendar; // used for computing current year /** Basic animal class for COMP1006/1406 tutorial. Example abstract

Need help with this program please!

image text in transcribed

image text in transcribed

ANIMAL CLASS: import java.util.Calendar; // used for computing current year /** Basic animal class for COMP1006/1406 tutorial. 

Example abstract class for tutorials in COMP 1006/1406. Students will complete the toString() class (overriding the method inherited from Object) and write subclasses that define the abstract method noise(). @author m. jason hinek @version 1.0 */ public abstract class Animal{ /** internal storage of animal's name

private/protected attributes and methods may or may not have javadoc documentation with them. If the javadoc is the API (interface) for the class, then users of the class should not know about these attributes and methods. It goes against the notion of information hiding if we make them visible like this. */ protected String name; /** internal storage of the animal's birth year */ protected int birthYear; /** Getter for an animal's name @return the name of this animal */ public String getName(){ return this.name; } /** Getter for an animal's year of birth @return the birth year of this animal */ public int getBirthyear(){ return this.birthYear; } /** Initializes an animal with the given name and birth year. @param name is the animal's name @param year is the animal's year of birth */ public Animal(String name, int year){ this.name = name; this.birthYear = year; } /** A string representation of the noise an animal makes.

The method must be overriden by child classes. @return a string representation of the noise an amimal makes */ public abstract String noise(); /* override Object's toString method here */ @Override public String toString(){ return "empty"; } }

CAT CLASS: public class Cat extends Animal{ }
DOG CLASS: public class Dog extends Animal{ }
Animal Consider the Aninal class provided. t is an abstract class to model animals. Read the class and see w hat it provides. Override Object's tostring) method in the Aninal class so that it prints out the animals name and age Note: assuming your computer's clock is correct, w e can get the current year in Java using java.uti1.Calendar now-Java.util.Calendar.getInstance() int year now.get (java.util.calendar.YEAR); Cat and Dog The cat and Dog classes should extend the animal class. Add any needed constructors and methods to make these w ork. Note: The noise that a cat makes should be either "meow" or "prrr (randomty chosen each time the noise method is called), and the noise a dog makes should be either "woof or "grrrr" (randomly chosen each time it's noise method is called) AnimalApp The AninalApp programgenerates an array of animals and calls the noise method of each. You can use this to test your Aninal Cat and Dog classes Owl Create an oul class that extends the Animal class. The class should have a three-argument constructor that takes a string (name), an integer (birth year) and a boolean (that determines if it is a wise owl or not). The string representation of an ow should include is name, age and w hether or not it is wise or not. An ow I's noise is hoooo. Modify the AninalApp program so that some owl objects are also created

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

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

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago

Question

=+3 In what ways can an MNE improve or change its approach to IHRM?

Answered: 1 week ago