Question

Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing...

Assignment Overview

This programming assignment is intended to demonstrate your knowledge of the following:

 Writing a while loop

 Writing a for loop

 Writing a while loop with a sentinel value Chocolate Coupons Foothill Fro-cho, LLC, gives customers a coupon every time they purchase a chocolate bar. After they earn a certain number of coupons, they qualify for a free chocolate bar, which they may use toward the purchase of a single chocolate bar. Usually, 7 is the number of coupons 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 coupons earn a free chocolate bar. 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 bars the customer wants to buy and then awards them one coupon for each chocolate bar. However, if, at the start of a new transaction, the system detects that the customer has previously earned 7 or more credits (= coupons), the system will inform the operator (customer or cashier) and give the operator the option of using 7 credits toward a free chocolate bar. The customer may accept the free chocolate bar, in which case the number of coupons in his account is decreased by 7, and a single free y chocolate bar is dispensed, or the customer declines, which turns this into a normal transaction, allowing the customer to purchase one or more bars, 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 coupon balance at 0. Then enter that loop which starts by giving the user two choices at each pass:  P (process a Purchase)  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. _________________________________________________________________________________________________________________ 2 Specifics of the P Selection If the operators choose '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 chocolate bars are being purchased, and add this number to the customer’s account/wallet/ coupons. At the end of the transaction, display the total/accumulated number of coupons earned so far, including the current transaction. Award Transaction Tell the user/operator that the customer qualifies for a free chocolate bar.

1. If the user opts for a free chocolate bar, give them one chocolate bar, display the new, reduced total number of coupons available and end the transaction, moving on to the next pass.

2. To keep things simple, we will not allow the purchase of multiple bars when an award chocolate bar is being redeemed. We reduce the number of credits by 7 (or whatever the qualifying number is for our system).

3. We don't add any credits/ coupons for the award chocolate bar. Even if the user has, say, 24 coupons, they can only get one chocolate bar in a single transaction, and the new balance will be 24 - 7 = 17, allowing the user to get another free chocolate bar on the next transaction.

4. 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 bars, and the corresponding number of coupons 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. CS 1A Assignment #5 Winter 2017 February 6, 2017 _________________________________________________________________________________________________________________ 3 Test Run Requirements: Submit at least two runs that show 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 chocolate bars 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 userinput error (an illegal choice) and one bad numeric input (out-of-range error). Use symbolic constants, not literals, for everything you can in this (and all) assignments. CLASS NAME. Your program class should be called ChocolateCoupons.java. Sample Run Here is an example of a partial working 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 chocolate bars would you like to buy? 14 You just earned 14 coupons and have a total of 14 to use. Menu: P (process Purchase) S (Shut down) Your Choice: P You qualify for a free chocolate bar. Would you like to use your credits? (Y or N) n How many chocolate bars would you like to buy? 21 You just earned 21 coupons and have a total of 35 to use. Menu: P (process Purchase) S (Shut down) Your Choice: p

_________________________________________________________________________________________________________________ 4 You qualify for a free chocolate bar. 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 chocolate bar. Would you like to use your credits? (Y or N) n How many chocolate bars would you like to buy? 2 You just earned 2 coupons and have a total of 37 to use. Menu: P (process Purchase) S (Shut down) Your Choice: proc You qualify for a free chocolate bar. Would you like to use your credits? (Y or N) y You have just used 7 credits and have 30 left. Enjoy your free chocolate bar. Menu: P (process Purchase) S (Shut down) Your Choice: s System shutting down. Good bye _________________________________________________________________________________________________________________ 5 Submission Instructions

 Execute the program and copy/paste the output that is produced by your program into the bottom of the source code file, making it into a comment. I will run the programs myself to see the output.

 Make sure the run "matches" your source. If the run you submit could not have come from the source you submit, it will be graded as if you did not hand in a run.

 Use the Assignment Submission link to submit the source code file.

 Submit the following file: o ChocolateCoupons.java.

 Do not submit .class files.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package com.vistara.web.controller.report;

import java.util.Scanner;

public class ChocolateCoupons {
   public static void main(String []args){
   String choice="";
   int coupons=0;
   int askedPrompt=1;
   while(true){
       if(askedPrompt!=0){
           Scanner sc=new Scanner(System.in);
           System.out.println("Menu: P (process Purchase) S (Shut down) Your Choice:");
           askedPrompt=0;
           choice = sc.nextLine();
       }
       if(choice.equalsIgnoreCase("p") || choice.equalsIgnoreCase("proc")){
       if(coupons>6){
           System.out.println("You qualify for a free chocolate bar. Would you like to use your credits? (Y or N)");
           Scanner sc3=new Scanner(System.in);
           String redeemChoice = sc3.nextLine();
           if(redeemChoice.equalsIgnoreCase("y") || redeemChoice.equalsIgnoreCase("yes")){
               coupons=coupons-7;
               System.out.println("You have just used 7 credits and have "+ coupons +" left. Enjoy your free chocolate bar.");
           }
           else if(redeemChoice.equalsIgnoreCase("n") || redeemChoice.equalsIgnoreCase("no")){
               System.out.println("How many chocolate bars would you like to buy?");
               askedPrompt=1;
               Scanner sc6=new Scanner(System.in); int chocos = sc6.nextInt();
             if(chocos>0){
                 coupons=coupons+chocos;
                 System.out.println("You just earned" +chocos+" coupons and have a total of "+coupons+" to use." );
             }
           }
           else{
               System.out.println("*** Invalid respose***");
               askedPrompt=1;
           }
       }
       else{
           System.out.println("How many chocolate bars would you like to buy?");
           askedPrompt=1;
           Scanner sc7=new Scanner(System.in);int chocos = sc7.nextInt();
           if(chocos>0){
               coupons=coupons+chocos;
               System.out.println("You just earned" +chocos+" coupons and have a total of "+coupons+" to use." );
           }
       }
       }
       askedPrompt=1;
       if(choice.equalsIgnoreCase("s") || choice.equalsIgnoreCase("shut")){
      System.out.println("System shutting down. Good bye" );
      break;
   }
   else{
       while(!(choice.equalsIgnoreCase("p")) && !(choice.equalsIgnoreCase("proc")) &&
           !(choice.equalsIgnoreCase("s")) && !(choice.equalsIgnoreCase("shut"))){
      System.out.println("*** Use P or S, please.***");
      System.out.println("Menu: P (process Purchase) S (Shut down) Your Choice:");
      askedPrompt=0;
      Scanner sc4=new Scanner(System.in); choice = sc4.nextLine();
   }
   }
       while(!(choice.equalsIgnoreCase("p")) && !(choice.equalsIgnoreCase("proc")) &&
           !(choice.equalsIgnoreCase("s")) && !(choice.equalsIgnoreCase("shut"))){
           System.out.println("Menu: P (process Purchase) S (Shut down) Your Choice:");
           askedPrompt=0;
           Scanner sc2=new Scanner(System.in); choice = sc2.nextLine();
       }
   }
  

   }
}

/*Menu: P (process Purchase) S (Shut down) Your Choice:
d
*** Use P or S, please.***
Menu: P (process Purchase) S (Shut down) Your Choice:
p
How many chocolate bars would you like to buy?
14
You just earned14 coupons and have a total of 14 to use.
Menu: P (process Purchase) S (Shut down) Your Choice:
P
You qualify for a free chocolate bar. Would you like to use your credits? (Y or N)
N
How many chocolate bars would you like to buy?
21
You just earned21 coupons and have a total of 35 to use.
Menu: P (process Purchase) S (Shut down) Your Choice:
P
You qualify for a free chocolate bar. Would you like to use your credits? (Y or N)
J
*** Invalid respose***
Menu: P (process Purchase) S (Shut down) Your Choice:
P
You qualify for a free chocolate bar. Would you like to use your credits? (Y or N)
N
How many chocolate bars would you like to buy?
2
You just earned2 coupons and have a total of 37 to use.
Menu: P (process Purchase) S (Shut down) Your Choice:
proc
You qualify for a free chocolate bar. Would you like to use your credits? (Y or N)
y
You have just used 7 credits and have 30 left. Enjoy your free chocolate bar.
Menu: P (process Purchase) S (Shut down) Your Choice:
s
System shutting down. Good bye*/     
     

import java.util.Scanner; public class ChocolateCoupons { public static void main (String []args) String choice-; int coupoelse System.out.println(How many chocolate bars would you like to buy?); askedPrompt-1; Scanner sc7-new Scanner(System.in);Menu: P (process Purchase) S (Shut down) Your Choice: Use P or S, please.*** Menu: P (process Purchase) S (Shut down) Your Ch

Add a comment
Know the answer?
Add Answer to:
Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪...

    C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪ Writing a while loop ▪ Write functions and calling functions Text Processing [50 points] We would like to demonstrate our ability to control strings and use methods. There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It...

  • Your assignment is to create a restaurant ordering system where the cashier can create the menu...

    Your assignment is to create a restaurant ordering system where the cashier can create the menu and then take in the order and display the order back to the customer Sample Execution – Level 1 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter item #2: Tea This is the menu: Coffee Tea What would you like to order? Cake That isn’t on...

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • This is done in c programming and i have the code for the programs that it wants at the bottom i ...

    This is done in c programming and i have the code for the programs that it wants at the bottom i jut dont know how to call the functions Program 2:Tip,Tax,Total int main(void) {    // Constant and Variable Declarations    double costTotal= 0;    double taxTotal = 0;    double totalBill = 0;    double tipPercent = 0;    // *** Your program goes here ***    printf("Enter amount of the bill: $");    scanf("%lf", &costTotal);    printf("\n");    // *** processing ***    taxTotal = 0.07 * costTotal;    totalBill...

  • Language: C# In this assignment we are going to convert weight and height. So, the user...

    Language: C# In this assignment we are going to convert weight and height. So, the user will have the ability to convert either weight or height and as many times as they want. There conversions will only be one way. By that I mean that you will only convert Pounds to Kilograms and Feet and Inches to Centimeters. NOT the other direction (i.e. to Pounds). There will be 3 options that do the conversion, one for each type of loop....

  • INSTRUCTIONS 1. Prompt the user for the number of participating units and expected peak demand hours...

    INSTRUCTIONS 1. Prompt the user for the number of participating units and expected peak demand hours 2. Create two arrays: O A String array called unitstatus, with an array element count equal to the number of participating units o An int array called unitCredit, with an array element count equal to the number of participating units O HINT: make sure you understand the difference between array size (element count) and element index (position) 3. Initialize the arrays, setting each element...

  • I really need help with this python programming assignment asap please double check indentations, thank you...

    I really need help with this python programming assignment asap please double check indentations, thank you We were unable to transcribe this imageEnter a drink option: Milk 22 Guest #1: a Please select the number of your entree choice 1) Planked salmon, 2) Prime rib, 3) Sesame tofu with spinach: 3 Please select the number of your dessert choice 27 1) Caramel oat bar, 2) Chocolate decadence, 3) Orange creme brulee: 1 Please select the number of your drink choice...

  • Assignment Overview This assignment is intended to demonstrate your comprehension of the primary applications of health...

    Assignment Overview This assignment is intended to demonstrate your comprehension of the primary applications of health informatics in healthcare organizations as well as your familiarity with the various informatics applications such as electronic health records (EHR) and telemedicine. For this assignment, you will read a case study that examines issues concerned with data standardization in informatics. Based on the scenario described in the case study, you will create a presentation related to informatics education and training. Case Study Read the...

  • Use your Car class from the previous Programming Assignment. For this assignment, create a new class...

    Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...

  • Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you...

    Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you some experience with writing functions that take in arguments and return values, as well as writing a program that consists of multiple files. This assignment also requires the use of a switch statement, in addition to more practice with printf& scanf declaring variables, using loops, and using logical expressions. For this assignment, you will prompt the user in the main function to enter their...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT