Question

In: Computer Science

Java Programing Display any welcome message at the top of the output screen Create following variables:...

Java Programing

Display any welcome message at the top of the output screen

Create following variables:

Price for a cup of coffee (make it adjustable within the program)

Number of cups (response from User)

Tax Rate in San Diego is 8%. Define 8% as a CONSTANT variable that never changes

Payment Method (Cash, Credit Card, Store Credit, Gold)

Ask the customer for their first name, and store it as a String object.

Ask the customer (by name) how many cups of coffee they would like to order and save that value.

Calculate the Total (# of cups * Price per Cup) * Sales tax

Using the printf, make all currency data printed to the screen display 2 decimal places, and also a '$" sign.

Also use at least one Decimal Format print method .

Using a switch statement on the payment type

If the user entered 'm' or 'M', display "You are paying using money" to the screen.

If the user entered 'c' or 'C', display "You are paying by Credit Card" to the screen .

If the user entered 's' or 'S;, dispay "You are paying with Store Credit" to the screen.

If the user entered 'g' or 'G', display "You are paying with Gold" to the screen.

If the user entered anything else, display "Invalid payment type, no lemonade for you!", and end the program

Using an if statement, If the quantity is less than 1, then display "Get out of my store, you bum!" and exit the program

Using a single if-else-if statement (also called a multi-branch if-else statement)

If the total is less than $10 and the user is paying by credit card, display "Sorry, there is a $10 minimum purchase for credit card"

If the total is between $10 and $100 (including $10 and $100), and display "Thank you, you earned a free glass of Lemonade!"

If the quantity is greater than 50 or the total is greater than $100, display "I'm going to Disneyland!"

Example Output 1

Welcome to Dave's Java Hut.

Cup of Coffee: $2.00

What is your name? Billy

Hi Billy, how many cups of coffee would you like to order? 5

Subtotal: $10.00

Tax:      $0.80

Total:    $10.80

How will you be paying, Billy? (Enter 'm' for money, 'c' for credit card, 's' for store credit or 'g' for gold): m

** You are paying using money

** Thank you, you earned a free cup of coffee!

Thanks Billy, and have a nice day!

Solutions

Expert Solution

import java.util.*;

class CoffeeShop
{
   public static void main (String[] args)
   {
        Scanner scan = new Scanner(System.in);
        double price = 2;
        char paymentType;
        final double tax = 0.08;
      
       System.out.println("Welcome to Dave's Java Hut.");

        System.out.println("Cup of Coffee: $"+price);

        System.out.println("What is your name? ");
      
        String name = scan.next();

        System.out.println("Hi "+name+", how many cups of coffee would you like to order?");
      
        int quantity = scan.nextInt();
        if(quantity < 1)
       {
       System.out.println("Get out of my store, you bum!" );
       System.exit(0);
       }
      
        double subTotal = quantity*price;
      
        System.out.printf("\nSubtotal: $ %.2f",subTotal);

        System.out.printf("\nTax:      $ %.2f",tax);
      
        double total = subTotal+tax;
        System.out.printf("\nTotal:    $ %.2f",total);
      

        System.out.println("\nHow will you be paying, "+name+"? (Enter 'm' for money, 'c' for credit card, 's' for store credit or 'g' for gold");
      
        paymentType = scan.next().charAt(0); //extract first character of the string
        switch(paymentType)
        {
            case 'm':
            case 'M' : System.out.println("\n** You are paying using money");
                        break;
            case 'c':
            case 'C' : System.out.println("\n** You are paying using Credit Card");
                        break;
            case 's':
            case 'S' : System.out.println("\n** You are paying using Store Card");
                        break;
            case 'g':
            case 'G': System.out.println("\n** You are paying using Gold");
                        break;
              
            default: System.out.println("\nInvalid payment type, no lemonade for you!");
                        break;
        }

     
        if(total < 10 && paymentType == 'C'|| paymentType == 'c')
        System.out.println("\nSorry, there is a $10 minimum purchase for credit card");
        else if(total > 10 && total <100)
        System.out.println("\n** Thank you, you earned a free cup of coffee!");
        else if(quantity > 50 || total > 100)
        System.out.println("\nI'm going to Disneyland!");
      

        System.out.println("\nThanks "+name+", and have a nice day!");
   }
}


Output:

Welcome to Dave's Java Hut.

Cup of Coffee: $2.00

What is your name? Billy

Hi Billy, how many cups of coffee would you like to order? 5

Subtotal: $10.00

Tax:      $0.80

Total:    $10.80

How will you be paying, Billy? (Enter 'm' for money, 'c' for credit card, 's' for store credit or 'g' for gold): m

** You are paying using money

** Thank you, you earned a free cup of coffee!

Thanks Billy, and have a nice day!


Related Solutions

JavaScript Create a welcome message on your webpage using three variables At least two of the...
JavaScript Create a welcome message on your webpage using three variables At least two of the variables should be concatenated together Use document.write to add a statement about what is your favorite past time? Format the HTML document appropriately with a title, and the correct HTML structure to hold the JavaScript Create an array to share what your favorite color is. The array must have at least three values and be called via the index value Correctly link the JavaScript...
Give a Java Statement that will display a dialogue window with the following message. “Java looks...
Give a Java Statement that will display a dialogue window with the following message. “Java looks good”                                                                                                         2. Write a code in java – create a method “s”. Insert 10 floating-point numbers in it. Using iterator find the sum of those numbers.        3. Write a Java program to read integers (for ex: 2017). Display it one digit per line in reverse order. 7 1 0 2 Write a Program that inputs a double value. If the double value is greater...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
Create a PowersTable application that displays a table of of powers. ( Java Programing )
Create a PowersTable application that displays a table of of powers. ( Java Programing )
Need this in java .Create a simple login screen in java That lets people sign in...
Need this in java .Create a simple login screen in java That lets people sign in to the emergency room. It needs to ask for name, social,and DOB. Once all the information is received it then display the info back to them if any info is is missing have the program prompt the user to re enter their information.
Create a JavaFX program in java that does the following items: Display a drawing area of...
Create a JavaFX program in java that does the following items: Display a drawing area of dimension 500 x 400, with a black background. Provides a radio button group to allow the user to select one of the following three colors: red, green, and blue. Upon startup, the red radio button should be selected. Each time the user clicks in the drawing area, a circle of size 10 of the color selected by the radio button group in item 2...
Using Excel, create scatter plots and display the regression equations for the following pairs of variables:...
Using Excel, create scatter plots and display the regression equations for the following pairs of variables: “MedAge” versus “Sales/SqFt” In your report, include the scatter plots. For each scatter plot, designate the type of relationship observed (increasing/positive, decreasing/negative, or no relationship) and determine what you can conclude from these relationships. Sales/SqFt 701.97 209.93 364.92 443.04 399.20 264.64 571.59 642.25 461.45 638.82 484.38 581.09 267.71 572.84 586.48 368.73 351.47 458.24 987.12 357.45 405.77 680.80 368.02 303.95 393.90 562.12 494.88 310.07 373.46...
In C++ Instructions: Use a void function to print the following message (should be in welcome...
In C++ Instructions: Use a void function to print the following message (should be in welcome function) Welcome to the Event Scheduling program create 3 int arrays with 3 positions (one array for days one array for moths and one array for years) (should be in main) Create a file that contains the following (you can just create the file or write the file in the program) 1 / 26 / 2021 12 / 13 / 2020 2 / 1...
///create a main menu to enter choices such as "Welcome to any college" then please enter...
///create a main menu to enter choices such as "Welcome to any college" then please enter your choice of information when you press a key 1. view students. 2. insert student 3. remove student 4. exit...and student ID#, age, birthday, location, expected gradation date import java.util.Scanner; public class CourseCOM666 { private String courseName; private String [] students = new String[1]; private int numberOfStudents; public CourseCOM666(String courseName) { this.courseName = courseName; } public String[] getStudents(){ return students; } public int getNumberOfStudents(){...
7) Create the following using Java. Create a scanner Declare double variables for price and tax...
7) Create the following using Java. Create a scanner Declare double variables for price and tax Declare character variable reply Create do while loop Inside of do loop Prompt the console to display headline Product Price Check Prompt the user to enter initial price and relate to scanner Prompt the user to enter the tax rate and relate to scanner Calculate price which is equal to price multiply (1+tax/100) Display in console the cost after tax which is price Check...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT