Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 ( 4 marks ) : Write a program to record information about pets in a pet store. The information consists of objects stored

Question 1(4 marks): Write a program to record information about pets in a pet store. The information consists of objects stored in a list. The attributes in the objects are as follows: store_name (a class attribute set to the value "Pet Paradise") animal_type pet_name age cost The class is to have the following methods: __init____str__ print_store_name (a class method) check_animal_type The user will given a menu with the following options: Add a pet Print a list of all animals in the store Print total and average cost Save information to a file Load information from a file Quit You are to create an Exception class called PetCheck to check that the animal_type entered is either a dog, cat, bird or fish. All other types of animals should generate an error message. You should also check the entered menu option, age and cost and generate a ValueError message if a ValueError occurs (age is to be an int and cost is to be a float). You should also check when you print out the average cost for a ZeroDivisionError and generate and error message of this occurs. Create a function for each of the menu options (except Quit). You will need to pass your list to these functions and return the list from them. You may pass or return other fields also if needed. When you load information from a file, make sure to first clear the list. Loading a file is to replace any existing information in the list with the information from the file. REQUIREMENTS Your program must follow the instructions above. Your code must be based only on the materials covered in weeks 1 to 12 of the course. Your output must appear exactly like the following example (the text in bold indicates the user input). Sample Output: Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 3 Error: There are no pets in the store (divide by zero) Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 1 Enter animal type: dogEnter pet name: FidoEnter pet age: 2Enter cost of pet: 299.95 Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 1 Enter animal type: horseError: You can only select a dog, cat, bird, or fish Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 1 Enter animal type: catEnter pet name: Mister MittensEnter pet age: 1.5Error: Age must be entered as an integer Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 1 Enter animal type: catEnter pet name: Mister MittensEnter pet age: 1Enter cost of pet: cheapError: Cost must be entered as an integer or float Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 1 Enter animal type: catEnter pet name: Mister MittensEnter pet age: 1Enter cost of pet: 50 Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 2 Store name: Pet ParadiseFido (dog), age 2, $299.95Mister Mittens (cat), age 1, $50.00 Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 3 Store name: Pet ParadiseTotal cost of pets: $349.95Average cost of pets: $174.97 Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 4 Enter name of file to write: pets.csvFile written. Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 5 Enter name of file to read: pets.csvFile loaded. Menu:1) Add a pet2) Print a list of all animals in the store3) Print total and average cost4) Save information to a file5) Load information from a file6) QuitPlease select an option: 6 Goodbye.

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

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions