Question

write a java code to calculate a restaurant tip based on the diner’s satisfaction on a...

write a java code to calculate a restaurant tip based on the diner’s satisfaction on a scale of 1 – 5. The user will input the total bill and their rating. The program should output the tip percentage, tip amount, and total due. You must use a select statement instead of an if.
For a rating of 1, calculate a 10 % tip.
For a rating of 2, calculate a 12.5% tip.
For a rating of 3, calculate a 15 % tip.
For a rating of 4, calculate a 20 % tip.
For a rating of 5, calculate a 25 % tip.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class RestaurantTip {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter bill: ");
        double bill = scan.nextDouble();
        System.out.print("Enter rating: ");
        int rating = scan.nextInt();

        double tip = 0.0;

        switch (rating){
            case 1:
                System.out.println("Tip percentage: 10%");
                tip = bill*0.10;
                break;
            case 2:
                System.out.println("Tip percentage: 12.5%");
                tip = bill*0.125;
                break;
            case 3:
                System.out.println("Tip percentage: 15%");
                tip = bill*0.15;
                break;
            case 4:
                System.out.println("Tip percentage: 20%");
                tip = bill*0.20;
                break;
            case 5:
                System.out.println("Tip percentage: 25%");
                tip = bill*0.25;
                break;
        }

        System.out.println("Tip amount: "+tip);
        System.out.println("Total due: "+(bill+tip));
    }
}

Add a comment
Know the answer?
Add Answer to:
write a java code to calculate a restaurant tip based on the diner’s satisfaction on a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Need help with a Java application that will compute tip amounts based on user input....

    1. Need help with a Java application that will compute tip amounts based on user input. Please let me know what else my code could use. My code is below and I need help formatting the output and calculating the amount paid by each person. Your application will: ask the user for a restaurant name, a waiter/waitress name, a bill amount and the number of people splitting the bill calculate 10%, 15% and 20% tips on the bill amount calculate...

  • in C# Write an object-oriented program that can be used to determine the tip amount that...

    in C# Write an object-oriented program that can be used to determine the tip amount that should be added to a restaurant charge. Allow the user to input the total, before the taxes (9% of the total) and the tip charge of 15%. Produce output showing the calculated total amount due. Tax should be added to the bill before the tip is determined. i will rate if correct

  • Bill and Tip Calculator Write a C program to generate a receipt for a restaurant. Your...

    Bill and Tip Calculator Write a C program to generate a receipt for a restaurant. Your application should allow the user to enter the bill amount and allow them to decide if they would like to leave a 15 percent tip or not. ▪ Do not allow the user to enter a negative value for the bill. ▪ Display the bill amount, tax amount, tip amount, and total amount. ▪ To calculate the tip, multiply the bill amount by 0.15....

  • When you go to a restaurant you need to calculate the tip that you need to...

    When you go to a restaurant you need to calculate the tip that you need to give the waiter. Write a program that allows a user to enter the total bill, and whether g-good service, a-all right, n-not bad, p-poor. Percentages for the service levels are: g-good service=25%,a-all right=15%,n-not bad=10%,p-poor= 0% . Calculate the tip. Add validation of the input, round up the tip amount and change the background color to green for good service, pink for all right, orange...

  • IN C# Write a program to help a local restaurant automate its lunch billing system. The...

    IN C# Write a program to help a local restaurant automate its lunch billing system. The program should do the following: Show the customer the different lunch items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill. Assume that the restaurant offers the following lunch items (the price of each item is shown to the right of the item): Ham and Cheese Sandwich $5.00 Tuna Sandwich $6.00 Soup...

  • CIT 238 – Android Programming I Tip Calculator Create an app that will compute the tip...

    CIT 238 – Android Programming I Tip Calculator Create an app that will compute the tip on a restaurant bill. App should contain: • An EditText to allow the user to enter the total amount of the bill • RadioButtons to allow the user to select one of the given tip percentages o 10% tip o 15% tip o 20% tip • A Button to calculate the amount of the tip. • A TextView to display the tip amount (tip...

  • Write a Java program that prompts user to select one of the five shapes(Rectangle, Square, Triangle,...

    Write a Java program that prompts user to select one of the five shapes(Rectangle, Square, Triangle, Circle, and Parallelogram), then calculate area of the shape,must have input validation and uses more of java library like math class, wrapper class, string methods, use formatted output with the printf method. Finally, create a pseudo-code statement and flowchart

  • Write a C  program that computes the tax and tip on a restaurant bill for a patron...

    Write a C  program that computes the tax and tip on a restaurant bill for a patron with a $88.67 meal charge. The tax should be 6.75 percent of the meal cost. The tip should be 20 percent of the total after adding the tax. Display the meal cost, tax amount, tip amount, and total bill on the screen.

  • Write a java code based on the below question. Q4 revision: Assume the following is ur...

    Write a java code based on the below question. Q4 revision: Assume the following is ur input file. 5 Rectangle Length Width A 3 B 7 6 с 3 8 Write a program to read the above input file, then calculate the area of each rectangle. The output should be stored in output file. You also have to identify which rectangle has the biggest sizs. 17:30

  • Python Simple Programming Write a program in Python that calculates the tip and total for a...

    Python Simple Programming Write a program in Python that calculates the tip and total for a meal at a restaurant. When your program is run it should ... Calculate the tip and total for a meal for a restaurant Print the name of the application "Tip Calculator" Get input from the user for cost of meal and tip percent Print the tip and total amounts. The formula for calculating the tip amount is: tip = cost of meal * (tip...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT