Question
Foothill Fro-Yo, LLC, gives customers a stamp every time they purchase a yogurt. After they earn a certain number of stamps, they qualify for a
Foothill Fro-Yo, LLC, gives customers a stamp every time they purchase a yogurt. After they earn a certain number of stamps, they qualify for a free yogurt, which they may use toward the purchase of a single yogurt.
Usually 10 is the number of stamps that qualifies, but we will let this be a symbolic constant which we can change. But for the purposes of this section, let's say that 10 stamps earns a free yogurt.
The program will be an app that runs at the point-of-purchase (cash register counter). The customer or cashier will process a looping series of purchase transactions. Normally, each transaction asks how many yogurts the customer wants to buy and then awards them one stamp for each yogurt. However, if, at the start of a new transaction, the system detects that the customer has previously earned 10 or more credits (= stamps), the system will inform the operator (customer or cashier) and give the operator the option of using 10 credits toward a free yogurt. The customer may accept the free yogurt, in which case the number of stamps in his account is decreased by 10, and a single free yogurt is dispensed, or the customer declines, which turns this into a normal transaction, allowing the customer to purchase one or more yogurts, adding to the credits that the customer already has.
Besides offering a purchase transaction each pass of the main execution loop, the only other choice is for the operator to shut down the system for the day. So the main loop has two choices: P: process a Purchase, or S: Shut down. Because we don't have arrays yet, this has to be a single-customer system.
The Program Spec
Process transactions in main method. Start the user's stamp balance at 0. Then enter a user-input loop, which gives the user two choices at each pass of the loop:
P (process a Purchase)
S (Shut down.)
The user is allowed to enter a single character or an entire word, and the program continues until and unless the user has entered an "s", "S", "Shut down", "stratford", or any word beginning with an upper or lowercase 's', in which case the program should end. If the user enters a word that starts with any character other than a 'P' or 'S' (upper or lowercase), the letter is ignored and the main menu is repeated, starting a new loop.
Specifics of the P Selection
If the operators chooses "P" (or something compatible) the program checks to see how many credits the customer has. (Remember, in this simplified exercise, there is only one customer.) If there are fewer than the qualifying number (set to 10), then a normal transaction is executed. If there are 10 or more credits in the customer's account, an award transaction is executed.
Normal Transaction
Ask the user/operator how many yogurts are being purchased, and add this number to the customers account/wallet/stamps. Award Transaction Tell the user/operator that the customer qualifies for a free yogurt.
1. If the user opts for a free yogurt, give them one yogurt and end the transaction, moving on to the next pass. To keep things simple, we will not allow purchase of multiple yogurts when an award yogurt is being redeemed. We reduce the number of credits by 10 (or whatever the qualifying number is for our system). We don't add any credits/stamps for the award yogurt. Even if the user has, say, 24 stamps, they can only get one yogurt in a single transaction, and the new balance will be 24 - 10 = 14, allowing the user to get another free yogurt on the next transaction.
2. If the user opts to not take the award, then the sequence of events turns into a Normal Transaction, in which the user can request to purchase one or more yogurts and the corresponding number of stamps is credited to the customer's balance.
Input Errors
Whenever the user makes an input error, cancel the transaction and proceed to the next loop pass (i.e., don't end the program). Do not attempt to keep the user in some sort of micro user-input loop, forcing them to stay within that transaction.
Always check for invalid user input like an invalid character choice, a negative number or an out-of-range numeric value, before proceeding. If the user commits an error of any kind (a bad command letter such as 'T' or an out-of-range amount), print an error message and return to the top of the main loop which asks the user for another command: P or S.
There is one exception to the error check just described. When it is time for the user to enter a number, you can assume he does not type some non-numeric value. You don't have to test for this kind of non-numeric error.
Test Run Requirements
Submit at least two runs that shows everything. In each run, show several cycles (passes) of the loop. Demonstrate all options. Also demonstrate the capacity to get either single letters or entire words from the user, showing at least one user-input error (an illegal choice) and one bad numeric input (out-of-range error).
A (partial) sample run is given at the bottom of this page.
Use symbolic constants, not literals, for everything you can in this (and all) assignments.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started