Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class describing a Cat object. A cat has the following attributes: a name (String), a breed (String), an age (int) and a mood

Write a class describing a Cat object. A cat has the following attributes: a name (String), a breed (String), an age (int) and a mood (String). The mood of a cat can be one of the following: sleepy, hungry, angry, happy, crazy. The cat constructor takes as input a String and sets that value to be the breed. The Cat class also contains a method called talk(). This method takes no input and returns nothing. Depending on the mood of the cat, it prints something different. If the cats mood is sleepy, it prints meow. If the mood is hungry, it prints RAWR!. If the cat is angry, it prints hsssss. If the cat is happy it prints purrrr. If the cat is crazy, it prints a String of 10 gibberish characters (e.g. raseagafqa).

The cat attributes are all private. Each one has a corresponding public method called getAttributeName() (ie: getName(), getMood(), etc.) which returns the value of the attribute. All but the breed also have a public method called setAttributeName() which takes as input a value of the type of the attribute and sets the attribute to that value. Be sure that only valid mood sets are permitted. (ie, a cats mood can only be one of five things). There is no setBreed() method because the breed of a cat is set at birth and cannot change.

Test your class in another file which contains only a main method. Test all methods to make sure they work as expected.

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

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago