Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Cat. The Cat class should: Keep track of the name, breed, age of the cat in appropriate private instance variables. Have

Create a class called Cat. The Cat class should:

Keep track of the name, breed, age of the cat in appropriate private instance variables.

Have constructor(s) to create Cat objects.

Have appropriate getters and setters.

-------------------------------------------------------------------------------------------------------------------------------

Create a class called CatListHandler to keep track of the Cats in the caf.

This class is intended to handle everything with regards to keeping track of a list of cats that are actually owned by the Caf. It does this by instantiating an ArrayList whenever an object of CatListHandler is created. This ArrayList will hold Cat objects that represent all the cats that the caf owns.

Hint: CatListHandler only needs to be instantiated once every time the program runs. If you construct more than one CatListHandler object, then you are likely doing something incorrectly.

This class should have the following public interface:

public CatListHandler():

Constructor(s) that can take either no arguments or an array of Cat objects.

The constructor does not care if there are Cats with duplicate names.

Any cats supplied are added to an internal ArrayList of cats.

public boolean addCat(String, String, int) :

A method that takes cat information, creates a cat, and adds it to the ArrayList.

The Cat is cross-referenced with the ArrayList for duplicate names based on the name variable of the cat.

*NOT by the variable name of the Cat object.

If the Cat (based on name) is a duplicate, then the method fails. Otherwise, it succeeds.

returns True if it succeeds. False if it fails.

public boolean removeCat(String) :

A method that takes a SINGLE cat by name and removes it.

returns True if it succeeds. False if it fails.

public String getAllCats() :

A method that returns all readable list of all Cats in the list. The string returned will be in an already readable format containing all the attributes, including name, breed, and age.

public String getCatCount():

A method that returns the number of cats in the Caf in a short readable string.

-------------------------------------------------------------------------------------------------------------------------------

Create a class called CatListTester to test the CatListHandler class. Instantiate a CatListHandler object and test every method in the class thoroughly. Ensure that any data you print to the console is clearly labelled and described.

-------------------------------------------------------------------------------------------------------------------------------

Create a class called CatManager that will contain the main method of the program (and ONLY the main method).

When the program runs, it will enter a state that we could call the main menu. There will be a short display of text explaining the options available to the user. It will then wait for user input using Java.Util.Scanner

The user can:

Input addcat to specify they wish to add a cat. The program will then prompt the user to input each piece of Cat information with appropriate instructions displayed. The order will always be Name, Breed, and Age. i.e.:

The system prompts the user for the cats name.

The user inputs the name and presses enter.

The system then prompts them for the breed.

The user inputs the breed and presses enter.

The system then prompts them for the age.

The user inputs the age and presses enter.

CatListHandler.addCat() will be called to add the cat to the list of Cats.

Input removecat to specify they wish to remove a cat. The program will then prompt the user to input the name of the Cat they wish to delete.

CatListHandler.removeCat() will be called to remove the cat from the list of Cats.

Input showallcats to specify they wish to show all cats. The program will then display to the user a list of all the cats

CatListHandler.getAllCats() will be called to get the list of cats and to format the cats information into something readable.

Input shownumberofcats to specify they wish to show the number of cats in the Caf. The program will then display to the user the number of cats in the Caf.

CatListHandler.getCatCount() will be called to get the count of cats and to format the cat count into something readable.

Input sortcats to specify they wish to sort the list of cats. The program will sort the list of cats alphabetically by name and then display to the user whether it succeeded or failed.

Input sortcatsbyage to specify they wish to sort the list of cats by age. The program will sort the list of cats by age (oldest to youngest) and then display to the user whether it succeeded or failed.

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions