Question: Pet Shop - Java programming The Pet Shop sells a range of animals to customers who would like a pet. They have a range of

Pet Shop - Java programming

The Pet Shop sells a range of animals to customers who would like a pet. They have a range of animals on offer. Each animal sells for a distinct price. The manager of the pet shop wants to record the information about each pet as it is sold.

The following information is recorded about each animal:

What it is, e.g. cat, dog, bird, etc.

Whether it is a male or female

Its age in months

The price it is sold for

Additionally, the shop keeps track of the following information:

The total number of animals sold

The total number of cats sold

The total income from all sale

Tasks:

1-Create a project called Unit2PetShop, naming the class PetShopDriver.

2-Start writing an Animal class, which will have relevant attributes to describe each animal that is sold, and will have a constructor to set these attribute values according to parameters passed in.

3-Ensure there are accessors and mutators for each of the attributes of the Animal class.

4-Start writing the main method of the PetShopDriver class which will provide two stages. The first stage of the main program will be a loop which does the following:

a)Ask the user to enter the details required about another sale. Save these details in local variables. Create a new Animal object with the relevant attribute values being provided at instantiation time. You only need to remember the most recently instantiated Animal.

b)Display the details of the Animal that has just been sold, by obtaining the values by calling the accessor methods.

c)Ask whether another sale needs to be recorded. If the answer is no, then move to the second stage of the program.

5-Make relevant modifications to both the MainProgram and Animal class to allow the following things in the second stage of the main program:

a)Using a method of the Animal class, obtain and then display the total number of animals that were sold.

b)Using another method of the Animal class, obtain and then display the total number of cats sold.

c)Using several methods of the Animal class, determine the average price at which animals were sold at the pet shop, and display this value.

NOTE: You must call methods of the Animal class to obtain all necessary values - you cannot have variables in the MainProgram that keep track of this information.(Hint: the 'static' modifier is required).

6-Add validation to the input that is taken in from the user, i.e. ensure that the selling price is positive, that the type of animal is actually entered (reject inputs where string length is less than 3 characters), that the age is great than 0, and that the character entered for gender is either m or f. Any time invalid input is entered, tell the user so, and ask again for the required information.

Perform validation on the main loop of the program also. You may ask the user to enter y or n indicating whether they want to continue recording animal details. Perform validation to check that the user does actually enter y or n and not another character.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!