Question

In: Computer Science

JAVA Point of Sale System The McDowell Restaurant chain has asked you to write a menu...

JAVA Point of Sale System
The McDowell Restaurant chain has asked you to write a menu program for their new Fast-food
service machines. Your program already prints the following menu like this:
**********************************************************************
McDowell’s Restaurant
**********************************************************************
Make your selection from the menu below:
1. Regular Hamburger $1.50
2. Regular Cheeseburger $1.75
3. Fish Sandwich $2.50
4. Half-pounder with cheese $2.75
5. French Fries $0.99
6. Large Soft Drink $1.25
***********************************************************************
Select 1, 2, 3, 4, 5, or 6 ----- >
Your program must now read the customer’s selection and compute the total price of their
purchase, including 6.5% sales tax.
Input
The first line of input represents N, the number of test cases. The additional lines consists of a
sequence of integers scoped between 1 to 6. Each number should indicate a selection from the
above menu to be purchased.
Output
The program should print the sum of the orders plus tax as “Please pay $<dollars>”, where
<dollar> is the total amount of the purchase then conclude with “Thank you for eating at
McDowell’s”.


Sample Input Sample Output
1
1 4 4 5 3 1 Please pay $12.77
Thank you for eating at McDowell’s!

Solutions

Expert Solution

/******************************
* McDowellRestaurantChain.java
*
******************************/

import java.text.DecimalFormat;
import java.util.Scanner;

//The class: McDowellRestaurantChain
public class McDowellRestaurantChain {
   //menu and price are taken in a constant static array of equal length
   //where ith element in MENU array represent the (i+1)th menu name and
   //ith element in PRICE array represents the corresponding menu's price
   private static final String[] MENU = {"Regular Hamburger","Regular Cheeseburger","Fish Sandwich",
           "Half-pounder with cheese","French Fries","Large Soft Drink"};
   private static final double[] PRICE = {1.50,1.75,2.50,2.75,0.99,1.25};
  
   private static final double SALES_TAX = 0.065; //6.5% sales tax as constant
  
  
   //the main method
   public static void main(String[] args){
      
       printMenu(); //prints menu first
      
       Scanner sc = new Scanner(System.in); //create the keyboard scanner
      
       try{
           int numOfTestCases = Integer.parseInt(sc.nextLine()); //get the number of test cases
          
           //prompt for user entry for <numOfTestCases> times to compute total for each test case
           for(int i = 1; i <= numOfTestCases ; i++){
               //get the current line entries
               //expecting the entries as space separated integer
               String currentEntry = sc.nextLine();
               String[] data = currentEntry.split(" "); //split it by space
               int[] selections = new int[data.length];//create integer array of splitted data array length
              
               //conver string[] into int[]
               for(int p = 0 ; p < data.length; p++){
                   selections[p] = Integer.parseInt(data[p]);
               }
              
               printTotalPay(selections); //print the total pay using current tst case's selection
              
               System.out.println("Thank you for eating at McDowell’s!");
           }
       }catch(NumberFormatException nfe){
           System.out.println("Invalid input"); //if any issue with string to integer conversion
       }
      
       sc.close();//close scanner
   }
  
   /**
   * print the menu
   */
   private static void printMenu(){
       DecimalFormat df = new DecimalFormat("#.00");//this will be used to format the price in 2 decimal digit
       System.out.println("**********************************************************************");
       System.out.println("McDowell’s Restaurant");
       System.out.println("**********************************************************************");
       System.out.println("Make your selection from the menu below:");
       for(int i = 0; i < MENU.length; i++){
           System.out.println((i+1)+". "+MENU[i]+" "+"$"+df.format(PRICE[i]));
       }
       System.out.println("**********************************************************************");
       System.out.println("Select 1, 2, 3, 4, 5, or 6 ----- >");
   }
  
   /**
   * calculate and print total pay including sales tax
   * using the selections array
   * @param selections
   */
   private static void printTotalPay(int[] selections){
       double total = 0;
       DecimalFormat df = new DecimalFormat("#.00"); //this will be used to format the output in 2 decimal digit
       for(int currentSelection: selections){
           total = total + PRICE[currentSelection -1];//get the price from PRICE array
       }
       double finalTotal = total + (total * SALES_TAX);
      
       System.out.println("Please pay $"+df.format(finalTotal));
   }

}

======================================

OUTPUT

======================================

RUN1

**********************************************************************
McDowell’s Restaurant
**********************************************************************
Make your selection from the menu below:
1. Regular Hamburger $1.50
2. Regular Cheeseburger $1.75
3. Fish Sandwich $2.50
4. Half-pounder with cheese $2.75
5. French Fries $.99
6. Large Soft Drink $1.25
**********************************************************************
Select 1, 2, 3, 4, 5, or 6 ----- >
1
1 4 4 5 3 2
Please pay $13.04
Thank you for eating at McDowell’s!

RUN2

**********************************************************************
McDowell’s Restaurant
**********************************************************************
Make your selection from the menu below:
1. Regular Hamburger $1.50
2. Regular Cheeseburger $1.75
3. Fish Sandwich $2.50
4. Half-pounder with cheese $2.75
5. French Fries $.99
6. Large Soft Drink $1.25
**********************************************************************
Select 1, 2, 3, 4, 5, or 6 ----- >
3
1 4 4 5 3 1 2
Please pay $14.63
Thank you for eating at McDowell’s!
2 4 5 1 2 3 4 5 1 2
Please pay $19.41
Thank you for eating at McDowell’s!
2 2 2 3 1 3 4
Please pay $15.44
Thank you for eating at McDowell’s!


Related Solutions

answer in basic JAVA im in and INTRO JAVA CLASS Problem 2: Point of Sale System...
answer in basic JAVA im in and INTRO JAVA CLASS Problem 2: Point of Sale System The McDowell Restaurant chain has asked you to write a menu program for their new Fast-food service machines. Your program already prints the following menu like this: ********************************************************************** McDowell’s Restaurant ********************************************************************** Make your selection from the menu below: 1. Regular Hamburger $1.50 2. Regular Cheeseburger $1.75 3. Fish Sandwich $2.50 4. Half-pounder with cheese $2.75 5. French Fries $0.99 6. Large Soft Drink $1.25...
Create a menu in Java. A menu is a presentation of options for you to select....
Create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Buy Stock. B. Sell Stock X. Exit Enter your Selection: 3. Prompt for the value menuChoice....
JAVA - The Westfield Carpet Company has asked you to write an application that calculates the...
JAVA - The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor(width times length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs $8 per square foot would cost $960. (12 X 10...
Class, Let's create a menu in Java. A menu is a presentation of options for you...
Class, Let's create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Deposit Cash. B. Withdraw Cash X. Exit Enter your Selection: 3. Prompt for the...
Marlow Company purchased a point of sale system on January 1 for $3,400. This system has...
Marlow Company purchased a point of sale system on January 1 for $3,400. This system has a useful life of 10 years and a salvage value of $400. What would be the depreciation expense for the second year of its useful life using the double-declining-balance method? Select one: a. $544. b. $680. c. $600. d. $480.
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
1. Point-of-Sale System: We have two companies that can implement a point-of-sale system. Both with cost...
1. Point-of-Sale System: We have two companies that can implement a point-of-sale system. Both with cost $200,000 to implement. Company A says we will receive the following returns on our investment: Year 1: $85,000; Year 2: $25,000; Year 3: $30,000; Years 4–10: $10,000. Company B says we will receive the following returns on our investment: Year 1: $30,000; Year 2: $25,000; Year 3: $85,000; Years 4–10: $10,000. Using the payback method, which company should we use and Why?
Randy’s, a family-owned restaurant chain operating in Alabama, has grown to the point that expansion throughout...
Randy’s, a family-owned restaurant chain operating in Alabama, has grown to the point that expansion throughout the entire Southeast is feasible. The proposed expansion would require the firm to raise about $18.3 million in new capital. Because Randy’s currently has a debt ratio of 50% and because family members already have all their personal wealth invested in the company, the family would like to sell common stock to the public to raise the $18.3 million. However, the family wants to...
A local Birmingham-area restaurant chain introduced a new summer menu in its Vestavia Hills location, but...
A local Birmingham-area restaurant chain introduced a new summer menu in its Vestavia Hills location, but not its Mountain Brook location. Nightly revenue averaged $6,000 in Vestavia Hills and $4,000 in Mountain Brook before the menu change, but $7,000 in Vestavia Hills and $3,000 in Mountain Brook after the menu change. The difference-in-difference estimate of the increase in average nightly revenue attributable to the menu change is a.$4,000 b. $0 c.$1,000 d.$2,000.
A local Birmingham-area restaurant chain introduced a new summer menu in its Vestavia Hills location, but...
A local Birmingham-area restaurant chain introduced a new summer menu in its Vestavia Hills location, but not its Mountain Brook location. Nightly revenue averaged $8,000 in Vestavia Hills and $7,000 in Mountain Brook before the menu change, but $9,500 in Vestavia Hills and $8,000 in Mountain Brook after the menu change. a. The difference-in-difference estimate of the increase in average nightly revenue attributable to the menu change is b. In the previous question, the increase in average nightly revenue attributable...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT