Question

Problem Statement:
Chip’s Snack Bar sells chips ($1), soda ($1.25), hot dogs ($2) and coffee ($0.75).
Both Seniors (i.e., age >= 62) and Students are eligible for a 10% discount.
Seniors are not charged for coffee (regardless of the number ordered).
All sales are taxed at a rate of 6%.
Write a Java program to do the following:
1. Read in an order from the keyboard ( which contains the student status
[y/n], user age, number of chips, number of sodas, number of hot dogs, and
number of coffees, in that order), all on separate lines. The program should
display prompts to the user as shown in the sample interaction.
2. Display a message repeating the customer’s order.
3. Calculate and display the subtotal of the order BEFORE discounts and taxes
are applied.
4. Calculate the discount and taxes and display them. The tax should be
calculated AFTER the discounts have been applied.
5. Calculate and display the final total and thank the user.

Requirements:
In addition to fulfilling the interaction described above your program must also

1. Have the main class named ‘CashRegister’
2. Make use of constant variables SENIOR_AGE, DISCOUNT_RATE and
TAX_RATE.
3. Save intermediate calculations (e.g., subtotal, tax, etc.) in appropriately
named variables.
4. Read the input from keyboard.
5. Display the output in a manner consistent with sample interaction described
below.

Are you a student [y/n]? What is your age? 20 How many bags of chips would you like? How many sodas would you like? How many hot dogs would you like? How many cups of coffee would you like? Order summary .I 1 bags of chips 1 sodas 1 hot dogs 1 cups of coffee Subtotal: 5.0 Discount: 0.5 Tax: 0.27 Total: 4.77 Thank you for your order!

This is the output for a 20 year old student who ordered 1 chip, 1 sodas, 1 hot dog and 1 coffees.

Do not worry if you show more or fewer decimal places with the results.

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

CODE :

import java.util.Scanner;

public class CashRegister {

   public static void main(String[] args) {

       int chipsCost = 1;
       float sodaCost = 1.25f;
       int hotdogsCost = 2;
       float coffeeCost = 0.75f;
       double subtotal = 0;
       int SENIOR_AGE = 62;
       int DISCOUNT_RATE = 10;
       int TAX_RATE = 6;

       Scanner sc = new Scanner(System.in);

       System.out.println("Are you a student [Y/N]");
       char student = sc.next().charAt(0);
       System.out.println("What is your age ?");

       int age = sc.nextInt();
       System.out.println("How many bags of chips would you like ?");

       int chipsCount = sc.nextInt();

       double totalchips = chipsCost * chipsCount;

       System.out.println("How many sodas would you like ?");

       int sodasCount = sc.nextInt();

       double totalSodas = sodaCost * sodasCount;
       System.out.println("How many hotdogs would you like ?");

       int hotdogsCount = sc.nextInt();

       double totalHotdogs = hotdogsCost * hotdogsCount;
       System.out.println("How many cups of coffee would you like ?");

       int coffeesCount = sc.nextInt();
       double totalCoffees;

       if (age < SENIOR_AGE) {

           totalCoffees = coffeeCost * coffeesCount;
       } else {
           totalCoffees = 0;

       }

       System.out.println("Order Summary . . . .");

       System.out.println(chipsCount + " bags of chips ");
       System.out.println(sodasCount + " sodas");
       System.out.println(hotdogsCount + " hot dogs");
       System.out.println(coffeesCount + " cups of coffee");
      
       System.out.println("---------------");

       subtotal = totalchips + totalSodas + totalHotdogs + totalCoffees;

       System.out.println("sub total : " + subtotal);
      
       double totalDiscount=(subtotal*DISCOUNT_RATE)/100;
      
       System.out.println("Discount : " +totalDiscount);
      
       double totalTax=((subtotal-totalDiscount)*TAX_RATE)/100;
      
       System.out.println("Tax : "+totalTax);
      
       System.out.println("Total : "+(subtotal-totalDiscount-totalTax));
      
       System.out.println("Thank You for your order . . . Good Day ...");

   }

}

OUTPUT :

Are you a student [Y/N] What is your age 25 How many bags of chips would you like ? How many sodas would you like? How many hotdogs would you like ? How many cups of coffee would you like ? Order Summary... . 1 bags of chips 1 sodas 1 hot dogs 1 cups of coffee sub total 5.0 Discount 0.5 Tax: 0.27 Total 4.23 Thank You for your order . .. Good Day ..

Add a comment
Know the answer?
Add Answer to:
Problem Statement: Chip’s Snack Bar sells chips ($1), soda ($1.25), hot dogs ($2) and coffee ($0.75)....
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
  • 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...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Consider the information provided in the Hot Coffee Lawsuit. What might be the possible implications for...

    Consider the information provided in the Hot Coffee Lawsuit. What might be the possible implications for the Restaurant Industry? What might be a long term impact? In 1992, Stella Liebeck spilled scalding McDonald's coffee in her lap and later sued the company, attracting a flood of negative attention. It turns out there was more to the story. The case is now famous but when Stella Liebeck burnt McDonald's coffee she would never know that it would still be talked about...

  • <Program 1: 50 points> software.cpp A software company sells a package that retails for $99. Quantity...

    <Program 1: 50 points> software.cpp A software company sells a package that retails for $99. Quantity discounts are given according to the following table. Quantity Discount 10-19 20% 20-49 30% 50-99 40% 100 or more 50% Write a program that asks for today's date (you MUST use cin >> date. Do not use getline(cin, date)), the company name and the quantity they wish to buy and computes the total cost of the purchase. If the user enters a negative value...

  • Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a...

    Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the name and the price per unit for two different candies. Then, the customer is allowed to order as many units of each of the two candies as they would like. Lastly, an invoice (report) is generated (displayed to the screen) under the following rules: All units up to...

  • Develop a functional flowchart and then write a C++ program to solve the following problem. 1....

    Develop a functional flowchart and then write a C++ program to solve the following problem. 1. Create a text file named c1.txt and write your brand of computer (like Dell, HP, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your program will also read the brand of your computer from the keyboard. The process of the file creation (name of the file, mode for opening...

  • I need the pseudocode and python for the four attached problems: 1. (Chapter 5 - For...

    I need the pseudocode and python for the four attached problems: 1. (Chapter 5 - For Loop) Logic Technical College has a current tuition of $10,000 per year. Tuition is scheduled to increase by 5% each year. Using a FOR loop, design a program that calculates and displays the tuition each year for the next ten years, like so: The tuition for year 1 will be: 10500.00 The tuition for year 2 will be: 11025.00 ……….. (You, of course will...

  • Overview JAVA LANGUAGE PROBLEM: The owner of a restaurant wants a program to manage online orders...

    Overview JAVA LANGUAGE PROBLEM: The owner of a restaurant wants a program to manage online orders that come in. This program will require multiple classes. Summary class, customer class, order class and the driver class. Summary class This class will keep track of the cost of the order and output a summary, which includes the total for the order. The methods in this class are static. There are no instance variables, and instead uses an Order object that is passed...

  • C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playi...

    C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playing cards contains 52 cards. There are four suits (heart, diamond club +, spade+) and thirteen ranks (ace, 2 thru 10,jack, queen, king) per suit. Rank Numeric Value 10 10 10 10 gueen 10 Write a program that does the following: I. Simulates a randomized shuffling of a 52 card deck 2. Determines how many combinations of 21 exist in the deck by following...

  • 1. Print out information of PHP use phpinfo() function. 2. Write a program that check and...

    1. Print out information of PHP use phpinfo() function. 2. Write a program that check and print odd / even numbers (from number 1 to 100 using for/while loop). Display the results within an HTML table with 2 columns as shown below: NUMBERS RESULTS 1 ODD 2 EVEN 3 ODD HINT: use <table> tags to create a table, <th> tags for ‘Numbers’ and ‘Results’. Wrap code PHP inside HTML code. For example: ​<html> ​​<title>CHECK ODD or EVEN</title> ​​<body> ​​​<table> ​​​​<?php...

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