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 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()
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...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT