Question

In: Computer Science

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
***********************************************************************
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

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


Related Solutions

This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA Public Key (10 points) (Cyber Security) RSA is an asymmetric encryption scheme, where a public key is used to encrypt data and a different, private key decrypts that data. RSA public/private keys are generated from two prime numbers, typically very large ones. The idea behind RSA is based on the fact that its difficult to factorize very large integers. RSA public key generation is...
This is an intro to java question. Please post with pseudocode and java code. Problem should...
This is an intro to java question. Please post with pseudocode and java code. Problem should be completed using repetition statements like while and selection statements. Geometry (10 points) Make API (API design) Java is an extensible language, which means you can expand the programming language with new functionality by adding new classes. You are tasked to implement a Geometry class for Java that includes the following API (Application Programming Interface): Geometry Method API: Modifier and Type Method and Description...
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 ----- >...
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?
Intro to java Problem, Please provide code and Pseudocode. Not able to compile correct numbers. Problem...
Intro to java Problem, Please provide code and Pseudocode. Not able to compile correct numbers. Problem 7: Simple Calculator (10 points) (General) Calculators represent the most basic, general-purpose of computing machines. Your task is to reduce your highly capable computer down into a simple calculator. You will have to parse a given mathematical expression, and display its result. Your calculator must support addition (+), subtraction (-), multiplication (*), division (/), modulus(%), and exponentiation (**). Facts ● Mathematical expressions in the...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem 4: Player Move Overworld (10 points) (Game Development) You're the lead programmer for an indie game studio making a retro-style game called Zeldar. You've been tasked to implement the player movement. The game is top-down, with the overworld modeled as a 2d grid. The player's location is tracked by x,y values correlating to its row and column positions within that grid. Given the current...
This is an Intro to Java Question, Please respond with code and pseudocode. Problem 3: RSA...
This is an Intro to Java Question, Please respond with code and pseudocode. Problem 3: RSA Private Key (10 points) (Cyber Security) In the RSA algorithm, encrypting and decrypting a message is done using a pair of numbers that are multiplicative inverses with respect to a carefully selected modulus. In this task, you must calculate the modular multiplicative inverse for given set of values. What is the Modular Multiplicative Inverse? In mathematics, each operation typically has an inverse. For example,...
in java please Project 2: The Triangle Class Problem Description: Design a class named Triangle that...
in java please Project 2: The Triangle Class Problem Description: Design a class named Triangle that extends GeometricObject. The class contains: • Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. • A no-arg constructor that creates a default triangle. • A constructor that creates a triangle with the specified side1, side2, and side3. • The accessor methods for all three data fields. • A method named getArea() that...
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the...
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the maximum of those numbers. You can assume that the user will provide some command-line arguments when running the program (so you don’t have to worry about what to do if the user doesn’t provide any arguments -- that won’t happen). Also, you can assume that all the command line arguments will be floating-point numbers, i.e., numbers with a decimal point, like 2.95.
this is my assignment for intro to java tha i could not figure out, my system...
this is my assignment for intro to java tha i could not figure out, my system just crashed wit a lot of errors. thank for your help Create a new Java class inside your project folder. The name of the class should be: TempConverter Note that this means you should have the following line at the top of your program: public class TempConverter Write a program that allows the user to convert a temperature given in degrees Celsius or Fahrenheit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT