Question

In: Computer Science

jgrasp environment, java write a complete program that calculates a restaurant bill. Prompt the user for...

jgrasp environment, java

write a complete program that calculates a restaurant bill. Prompt the user for the check amount, then ask the user what type of tipp they would like to leave: the choices are 1 for good tip (20%), 2 for an average tip (15%), or 3 for poor tip (10%). Use their input and an if-else to calculate the tip amount. Then calculate and output the final bill:

check+tip

print out the bill, exactly as shown (print the dollar sign as a separate character before the dollar amounts.)

sample output:

total check: $20.0

tax: $1.4

tip (good): $4.0

final bill

both tax and tip are calculated using the initial check amount (dont tax the tip, and dont use ta when calculating the tip). without special formatting, the dollar amounts will not have two decimal places of precision, that is fine for this project.

Thank you.

Solutions

Expert Solution

import java.util.*;

class Bill
{
   public static void main (String[] args)
   {
       Scanner input = new Scanner(System.in);
       String type = "";
       double tax,tip;
       tip = 0.0;
      
       System.out.println("Enter the check amount : ");
       double check = input.nextDouble();
       tax = check*0.07;
      
       System.out.println("Enter the type of tip <1--- good tip(20%) , 2--- average tip(15%), 3--- poor tip(10%) : ");
       int tipType = input.nextInt();
      
       if(tipType == 1)
       {
           type = "good";
           tip = check*0.2;
          
       }
       else if(tipType == 2)
       {
           type = "average";
           tip = check*0.15;
       }
       else if(tipType == 3)
       {
           type = "poor";
           tip = check*0.1;
       }


       System.out.println("total check: $"+check);
       System.out.printf("tax: $%.2f",tax);
       System.out.println("\ntip ("+type+"): $"+tip);
       System.out.println("Final bill : $"+(check+tip));

   }
}

Output:

Enter the check amount : 20.0
Enter the type of tip  <1--- good tip(20%) , 2--- average tip(15%), 3--- poor tip(10%) : 1
total check: $20.0
tax: $1.40
tip (good): $4.0
Final bill : $24.0

Do ask if any doubt. Please upvote.


Related Solutions

jgrasp environment, java write a complete program that prompts the user to enter their first name,...
jgrasp environment, java write a complete program that prompts the user to enter their first name, middle name, and last name (separately). print out thier name and initials, exactly as shown: your name is: John Paul Chavez your initials are: J. P. C. use string method chartAt() to extract the first (zero-th) character from a name(the name is a string type): username.charAt(0). thank you.
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
Write a short, cohesive java program in jGrasp that interacts with the user and does the...
Write a short, cohesive java program in jGrasp that interacts with the user and does the following: create at least 2 double variables create at least 1 constant get at least 1 string input from the user get at least 1 int/double input from the user include both, incorporating the input you got from the user: 1 multiway if-else with at least 3 "else if" 1 nested if Your program should combine all of these into one cohesive, interactive program...
USING jgrasp environment, javascript rite a complete program that prompts the user for two integers and...
USING jgrasp environment, javascript rite a complete program that prompts the user for two integers and then prints the following report to the screen, exactly as shown. example, using 23 and 18 as the user input: your numbers are :23 and 18 sum=41 product=414 use the scanner class nextlnt() method to read the user's numbers: scanner keyboard... ...keyboard.nextlnt()
Write a java program that calculates a speeding fine. The user is prompted for the speed...
Write a java program that calculates a speeding fine. The user is prompted for the speed of the vehicle, the posted speed limit and if the offence took place in the construction zone. The fine is calculated at $75 + 3$/ km over the speed limit for the first 20km over + $6 / km for the next 20 and $9/km after that. If the posted limit is 40km, the fine is doubled. If the offence took place in a...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a java program that prompt the user to insert last term’s courses and their individual...
Write a java program that prompt the user to insert last term’s courses and their individual mark and store them in an appropriate multidimensional array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT