Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me about my Java homework.....I am really confused about how to do it The program will have a Pet class to model individual

Please help me about my Java homework.....I am really confused about how to do it

The program will have a Pet class to model individual pets and the Assignment5 class will contain the main and act as the pet store. Users will be able to view the pets, make them age a year at a time, add a new pet, and adopt any of the pets.

Requirements Your program must do the following in order to receive full credit on this assignment. 1. Create a new public class called Pet in its own file. a. Remember that class and file name must match. 2. Create three private instance variables. a. The name of the pet. b. The age of the pet. c. Whether the pet is adopted or not. 3. Create a default constructor for the Pet class. a. Remember that a default constructor takes no arguments and assigns meaningless values to the instance variables. 4. Create a second constructor for Pet that takes a name and age as arguments. a. Assign these values to the instance variables. b. Pets always start off un-adopted. 5. Provide a get and set for the name instance variable. 6. Provide a get for age, but instead of a regular set create a method that increases age by 1. a. Keep in mind that this age increase method will need to be public. 7. Provide a get for the adopted variable and instead of a set provide a public method which sets this adoption variable to true. a. Note: This is the last thing you will do in Pet. The rest of these steps are done in your main program file. 8. Create a Scanner object that will be visible to all methods in Assignment5. a. This object will need a particular modifier. What is it? 9. Create a private static String method which prints out the main menu of the program. It then accepts a String from the user and returns their choice. The commands to list are as follows. a. List the pets in the store. b. Age up the pets. c. Add a new pet. d. Adopt a pet. e. Quit. i. Your method must verify that the user typed in a valid input before returning the input. 10. Within the programs main method, create two local pet objects. a. The first is named Fido and is 3 years old. b. The second is named Furball and is 1 year old. 11. Create a third local pet object, but do not create a new pet object yet. a. This represents the pet that the user can add later. b. What should this be initialized as? i. Theres a special value for objects that dont exist yet. 12. Print out a welcome message, and then call your main menu method to display the menu and get the users first input. 13. Create a while loop that will run until the user types in the exit command at the menu. a. After the loop print a goodbye message. 14. Within the loop determine which menu choice the user picked and do the appropriate action. The different possible actions are defined in the following steps. a. Dont forget to take a new input from the user after youve processed their choice. 15. If the user chose to print the pets, print out the information about each pet. a. For example: Fido is 3 years old and is not adopted.. b. If the pet is only 1 year old, it should say year instead of years. c. If the pet is adopted, it should say they are adopted instead. d. See example inputs. e. Be careful to not try to print the third pet if it hasnt been added yet! 16. If the user chose to make all the pets one year older, invoke your method to age the pet up by one year on all the pet objects. a. Again, be careful about the third pet! 17. If the user chose to add a new pet, accept a name and age from the user and create a new pet object for the third pet. a. If there already is a third pet, print an error message instead. b. You do not have to validate the name or age in any way. You can assume the user types in valid values. 18. Finally, if the user chose to adopt a pet, ask them to type in the number of the pet they want. a. This number corresponds with the order in which they are printed out. b. Verify that they typed in a valid number for an existing pet. i. This means if pet three hasnt been added then 3 is invalid. c. Check if the pet is already adopted and print a message if it is already adopted. d. Otherwise, change its status to adopted. Note: Now that you know how to write methods, dont be afraid to write extra methods for any common tasks you may have. You need at least the methods described above, but some other parts may work well as methods as well. Example Inputs Below are five example runs of the program with the inputs and outputs.

Example output1:

Welcome to the pet store!

Type the letter to make your selection.

A. List the pets in the store.

B. Age up the pets.

C. Add a new pet.

D. Adopt a pet.

E. Quit

A

Fido is 3 years old and is not adopted.

Furball is 1 year old and is not adopted.

Type the letter to make your selection.

A.list the pets in the store.

B.Age up the pets.

C.Add a new pet.

D. Adopt a pet.

E.Quit

E

Have a good day!

Example output2:

Welcome to the pet store!

Type the letter to make your selection.

A. List the pets in the store.

B.Age up the pets

C.Add a new pet.

D.Adopt a pet.

E.Quit.

A

Fido is 3 years old and is not adopted.

Furball is 1 year old and is not adopted.

Type the letter to make your selection.

A.List the pets in the store.

B. Age up the pets.

C. Add a new pet.

D.Adopt a pet.

E.Quit.

B

Everyone just got a little older.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

A

Fido is 4 years old and is not adopted.

Furball is 2 years old and is not adopted.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

E

Have a good day!

Example output3:

Welcome to the pet store!

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

C

Please type in a name.

Rex

Type in an age

10

Rex has arrived in the store.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

C

Sorry, the store is full.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

A

Fido is 3 years old and is not adopted.

Furball is 1 year old and is not adopted.

Rex is 10 years old and is not adopted.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

E

Have a good day!

Example output4:

Welcome to the pet store!

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

D

Type the number of the pet you would like to adopt.

The number is the order they appear in the list.

3

That is not a valid pet.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

D

Type the number of the pet you would like to adopt.

The number is the order they appear in the list.

2

Furball was adopted!

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

E

Have a good day!

Example output5:

Welcome to the pet store!

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

a

Invalid choice

A

Fido is 3 years old and is not adopted.

Furball is 1 year old and is not adopted.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

Q

Invalid choice

B

Everyone just got a a little older.

Type the letter to make your selection.

A. List the pets in the store

B. Age up the pets

C. Add a new pet

D. Adopt a pet

E. Quit

f

Invalid choice

E

Have a good day!

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