Trusted by Students Everywhere
Why Choose Us?
0% AI Guarantee

Human-written only.

24/7 Support

Anytime, anywhere.

Plagiarism Free

100% Original.

Expert Tutors

Masters & PhDs.

100% Confidential

Your privacy matters.

On-Time Delivery

Never miss a deadline.

PROGRAMMING PRINCIPLES ASSIGNMENT In this assignment, you will write a Cat class so that you can create a cat object and interact with it

Computer Science Aug 09, 2021

PROGRAMMING PRINCIPLES ASSIGNMENT

In this assignment, you will write a Cat class so that you can create a cat object and interact with it. Create class Cat. This class should have the following:

  • name attribute that is intialized when a cat is created.
  • An energy attribute that has an initial value of 2.
  • stomach capacity attribute that has an initial value of 2.
  • A method called play(). If the value of energy is greater than 0, it prints a message similar to "catname says meow" and then reduces the value of energy by 1. The message has to contain the name of the cat and the sound meow. However, if the value of energy is less than or equal to 0, it prints "catname is tired" instead.
  • A method called eat(). If the capacity of stomach is greater than 0, it prints a message similar to "catname says nom" and then reduces the capacity of stomach by 1. The message has to contain the name of the cat and the sound nom. However, if the capacity of stomach is less than or equal to 0, it prints "catname is full" instead.

         In main(), you should have the following:

  • The program asks the user to enter a name and then creates a cat object with that name.
  • The program then asks how the user would like to interact with the cat by entering either 'play' or 'feed'.
  • Once the user enters the option, the program calls the corresponding methods from the Cat class to perform the interaction.
  • Once the interaction is completed, the program should ask if the user would like to continue. If the user enters 'y', the program will again ask how the user would like to interact with the cat. If the user enters 'n', the program will end. The user can enter either a capital letter or a lowercase letter.

 

     Below is a screenshot of expected result from running the program.

Compare your final result with the screenshot to verify. Look for small things such as upper or lower cases or extra white spaces, etc.

 

A screenshot of the expected result.

 

Archived Solution
Unlocked Solution

You have full access to this solution. To save a copy with all formatting and attachments, use the button below.

Already a member? Sign In
Important Note: This solution is from our archive and has been purchased by others. Submitting it as-is may trigger plagiarism detection. Use it for reference only.

For ready-to-submit work, please order a fresh solution below.

Or get 100% fresh solution
Get Custom Quote
Secure Payment