can someone help me with this please it is from code hs the lesson…

can someone help me with this please it is from code hs the lesson name is Inventory this are the instructions 

Write a program that keeps track of a simple inventory for a store. While there are still items left in the inventory, ask the user how many items they would like to buy. Then print out how many are left in inventory after the purchase. You should use a while loop for this problem. A sample run is below.

We have 20 items in inventory.
How many would you like to buy? 4
Now we have 16 left.

We have 16 items in inventory.
How many would you like to buy? 2
Now we have 14 left.

We have 14 items in inventory.
How many would you like to buy? 8
Now we have 6 left.

We have 6 items in inventory.
How many would you like to buy? 5
Now we have 1 left.

We have 1 items in inventory.
How many would you like to buy? 1
Now we have 0 left. 

All out

Make sure you catch the case where the user tries to buy more items than there are in the inventory. In that case, you should print a message to the user saying that their request isn’t possible. For example:

We have 5 items in inventory.
How many would you like to buy? 6
There is not enough in inventory for that purchase.

We have 5 items in inventory.
How many would you like to buy? 5
Now we have 0 left. 

All out!

IMPORTANT
In order to pass the test cases and the assignment, your output should look like the samples above, including the blank line between each run. This blank line helps break up the output so that it is easier for the user to read.

You can easily create a blank line by adding a print statement like println(“”) at the appropriate place in your code.

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions