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...
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 a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
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
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 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...
Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
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...
Write a java program that asks the user for a positive integer N and then calculates...
Write a java program that asks the user for a positive integer N and then calculates a new value for N based on whether it is even or odd: if N is even, the new N is N/2. (Use integer division.) if N is odd, the new N is 3*N + 1. Repeat with each new N until you reach the value 1. For example, say the initial value is 12. Then the successive values are: 12 (even, next value...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT