In: Computer Science
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
***********************************************************************
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!
import java.util.Scanner;
import java.util.*;
import java.io.*;
import java.text.DecimalFormat;
public class Restaurant
{
//set the number of decimal places
private static DecimalFormat df = new DecimalFormat("0.00");
//driver program
public static void main(String[] args)
{
//create the scanner object
Scanner scnr = new Scanner(System.in);
int i=0,n,j;
int a[] = new int[50];
double price=0,tax=0;
//declare and initialize the values of prices
double p[]={1.5,1.75,2.5,2.75,0.99,1.25};
//ask for number of test cases
System.out.println("Enter how many test cases do you want ?
");
n=scnr.nextInt();
//loop for number of test cases
while(n>0)
{
price=0; //set price to 0 for all test cases
//display the menu
System.out.println("******************************************");
System.out.println("1. Regular Hamburger $1.50");
System.out.println("2. Regular Cheeseburger $1.75");
System.out.println("3. Fish Sandwich $2.50");
System.out.println("4. Half - Pounder with cheese $2.75");
System.out.println("5. French Fries $0.99");
System.out.println("6. Large Soft Drink $1.25");
System.out.println("******************************************");
System.out.println("Enter the options,Enter 0 to stop");
//read the options
for(i=0;;i++)
{
a[i]=scnr.nextInt();
if(a[i]==0)//loop terminating condition
break;
//condition for invalid entry
if(a[i]<1 || a[i]>6)
{
System.out.println("Invalid choice");
i--;
}
}
//compute the total price
for(j=0;j<i;j++)
{
price = price + (p[a[j]-1]);
}
//add the tax to price
price = price + (price * 0.065);
//deiplay the total amount
System.out.println("Please pay $"+df.format(price));
n--; //decrease n for nexxt test cases
}
//display the message
System.out.println("Thank you for eating McDowell's!");
}
}
output