You are writing an inventory system for a library. This program will allow the user to enter a book, remove a book, and find a book. The book titles will be stored in a dictionary. Each key in the dictionary is a book’s title, and each value is the number of copies currently in stock.  In a continuous loop, give the user the option to add a book, remove a book, find a book, and quit.  If the user chooses to add a book, call a function named add_book. This function should ask for a book title and how many copies the user is adding. If the title is not yet in the dictionary, add a new key/value pair to the dictionary with the key being the book title and the value being the amount the user is adding. If the title is already in the dictionary, update its value to include the copies the user is adding. If the user chooses to find a book, call a function named find_book which asks the user for a book title. If the book’s title exists in the dictionary, print out how many copies of it are currently in stock. Otherwise, print that no copies are in stock.  If the user chooses to remove a book, call a function named remove_book. In this function, ask the user to enter a title. If the title exists in the dictionary, remove a single copy (unless there are 0 in stock, in which case tell the user the removal cannot happen and return).  After removal, if there are no more copies in stock, ask the user if they would like to keep the book in the system with its amount set to 0 or if they would like to remove it from inventory altogether. Hint: If the user chooses to remove the key/value pair from the dictionary, you may want to refer to the very end of lecture 12 for info on how to remove a specific key/value pair from a dictionary.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 8PE
icon
Related questions
Question

You are writing an inventory system for a library. This program will allow the user to enter a book, remove a book, and find a book. The book titles will be stored in a dictionary. Each key in the dictionary is a book’s title, and each value is the number of copies currently in stock. 

In a continuous loop, give the user the option to add a book, remove a book, find a book, and quit. 

  • If the user chooses to add a book, call a function named add_book. This function should ask for a book title and how many copies the user is adding.
    • If the title is not yet in the dictionary, add a new key/value pair to the dictionary with the key being the book title and the value being the amount the user is adding.
    • If the title is already in the dictionary, update its value to include the copies the user is adding.
  • If the user chooses to find a book, call a function named find_book which asks the user for a book title. If the book’s title exists in the dictionary, print out how many copies of it are currently in stock. Otherwise, print that no copies are in stock. 
  • If the user chooses to remove a book, call a function named remove_book. In this function, ask the user to enter a title. If the title exists in the dictionary, remove a single copy (unless there are 0 in stock, in which case tell the user the removal cannot happen and return). 
    • After removal, if there are no more copies in stock, ask the user if they would like to keep the book in the system with its amount set to 0 or if they would like to remove it from inventory altogether. Hint: If the user chooses to remove the key/value pair from the dictionary, you may want to refer to the very end of lecture 12 for info on how to remove a specific key/value pair from a dictionary.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT