How many yogurts would you like to buy

Assignment Help JAVA Programming
Reference no: EM131590967

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 7 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 7 stamps earn 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 7 or morecredits (= stamps), the system will inform the operator (customer or cashier) and give the operator the option of using 7 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 7, 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 a main loop. Start the user's stamp balance at 0. Then enter that loop which starts by giving the user two choices at each pass:
P(process aPurchase)
S(Shut down.)
The user is allowed to enter a single character or an entire word or even multiple words separated by spaces and the program continues until and unless the user has entered an "s", "S", "Shut down", "stratford", "support your local CC", or any word/phrase beginning with an upper or lower case 's', in which case the program should end. If the user enters a word/phrase that starts with any character other than a 'P' or 'S' (upper or lower case), the letter is ignored and the main menu is repeated, starting a new loop.
Specifics of the P Selection
If the operators chooses 'P', then 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 7), then a normal transaction is executed. If there are 7 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. At the end of the transaction, display the total/accumulated number of stamps earned so far, including the current transaction.
Award Transaction
Tell the user/operator that the customer qualifies for a free yogurt.
If the user opts for a free yogurt, give them one yogurt, display the new, reduced total number of stamps available 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 7 (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 - 7 = 17, allowing the user to get another free yogurt on the next transaction.
If the user opts to not take the award, then the sequence of events turns into aNormal 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.
Do Not Use Methods
Even though we may have started reading about methods, don't use them for this assignment. We haven't completed their study and you will likely lose points for incorrect usage.
Test Run Requirements:
Submit at least two runs that shows everything. In each run, show several cycles (passes) of the loop. Specifically, in at least one run include at least 6 purchase transactions and at least two free yogurts along with the invalid input. Beyond that, make sure you 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) assignment.
Sample Run:
Menu:
P (process Purchase)
S (Shut down)

Your Choice: d

*** Use P or S, please. ***

Menu:
P (process Purchase)
S (Shut down)

Your Choice: push

How many yogurts would you like to buy ?
14

You just earned 14 stamps and have a total of 14 to use.

Menu:
P (process Purchase)
S (Shut down)

Your Choice: P

You qualify for a free yogurt. Would you like to use your credits? (Y or N)
n

How many yogurts would you like to buy ?
21

You just earned 21 stamps and have a total of 35 to use.

Menu:
P (process Purchase)
S (Shut down)

Your Choice: p

You qualify for a free yogurt. Would you like to use your credits? (Y or N)
j

*** Invalid response ***

Menu:
P (process Purchase)
S (Shut down)

Your Choice: p

You qualify for a free yogurt. Would you like to use your credits? (Y or N)
n

How many yogurts would you like to buy ?
2

You just earned 2 stamps and have a total of 37 to use.

Menu:
P (process Purchase)
S (Shut down)

Your Choice: proc

You qualify for a free yogurt. Would you like to use your credits? (Y or N)
y

You have just used 7 credits and have 30 left.
Enjoy your free yogurt.

... etc.

Reference no: EM131590967

Questions Cloud

Is the united states an economically just society : Is the United States an economically just society? Why or why not? Which view of corporate social responsibility-the narrow or the broad-do you favor, and why?
What is the emissivity of the wall : Heat is conducted through the wall. The outside of the wall loses the energy only due to radiation. What is the emissivity of the wall?
Explain outcomes from stop and frisk policies : What are the outcomes. Do you agree that these are the outcomes. Do you agree with the ACLU recommendations
Explain what about the death penalty : Why does sentencing disparity exist. Is it a problem. What about the death penalty, is it an effective deterrent. How can it be improved
How many yogurts would you like to buy : You qualify for a free yogurt. Would you like to use your credits - How many yogurts would you like to buy - which they may use toward the purchase of a single
Define the agile delivery framework : Explain why there is no such thing as a best practice, but rather there are only good practices for a given situation for an Agile project.
Define criminal justice management classes : how to locate good information for my essay. also I always have a struggle when it come to the abstract area of an essay
What is the emissivity of the wall : Heat is conducted through the wall. The outside of the wall loses the energy only due to radiation. What is the emissivity of the wall?
Analyze why did you select the specific components you did : Analyze why did you select the specific components you did? Is there a "best practices checklist" that can be created for analyzing emerging markets?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a menu-driven java program

Write a menu-driven JAVA program that performs the following array/vector operations:

  Understanding of basic programming concepts

Demonstrate understanding of basic programming concepts by: 1. Constructing a simple flowchart that describes simple logic flow through a program;

  Inheritance involves the concept of super class

Inheritance involves the concept of super class (parent class) and sub class (derived class). What is a super class in Java? What is a sub or derived class in Java?

  Java program that can be used to read a list of values

Java program that can be used to read a list of values from the standard input and display the following information based on the values read: 1. All of the positive numbers and the count. 2. All of the negative numbers and the count.

  Develop an app using the volley framework

Develop an app using the Volley framework that retrieves JSON data from the NASA website and displays in a listview

  Create the java source code files for the classes listed in

Create an abstract base class, Animal. The single constructor requires a String to indicate the type of animal, which then is stored in an instance variable.

  Write a program that creates an apartment object and prompts

Create a structure named Apartment that contains data fields to hold the number of bedrooms, the number of bathrooms, and the monthly rent for the apartment.

  Displays the calendar for the current month

Prepare a program that displays the calendar for the current month. You will use the Prior and next buttons to show the calendar of the previous or next month.

  Write a program that reads customers information from file

User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

  Relationship between inheritance and subtyping

With this declaration of m in subclass B, any invocation of m on a B object will result in a special error indicating that the method should not be used. (a) What effect does this feature of Smalltalk have on the relationship between inherit..

  Create a java gui app implement inside a main method

Create a Java GUI app, implement the following criteria inside a main method 1) set up a visible frame with width 500, height 300; 2) frame title is "CSE205 Frame app"; and 3) setDefaultCloseOperation to EXIT_ON_CLOSE.

  Alicia creates a button using the code jbutton exit button

Alicia creates a button using the code JButton exitButton = new JButton("exit"); and places it into a JFrame named mainFrame

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd