Question

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 the amount paid by each person
  • display all input values and the calculated values in table format

A sample run of your application is below (user input is in bold):

Which restaurant?  TGIFridays

What is your server's name? Tony

What is your bill amount? 24.13

How many people in your party? 4

Sample output is below:

Restaurant: TGIFridays

Server: Tony

Original Bill: $24.13

with 10% tip
$26.54
everyone pays: $ 6.64

with 15% tip
$27.75
everyone pays: $6.94

with 20% tip
$28.96
everyone pays: $7.24

import java.util.Scanner;

public class TipCalc
{

public static void main(String [] args)
{

Scanner input = new Scanner(System.in);
double billAmount;
int numOfPeople;
double tip1, tip2, tip3;
double totalAmount1, totalAmount2, totalAmount3 = 0;
  
  
//input
System.out.print("Which restaurant? ");
String restaurant = input.next();
System.out.print("What is your servers name? ");
String server = input.next();
System.out.print("What is your bill amount? ");
billAmount = input.nextDouble();
System.out.print("How many people in your party? ");
numOfPeople = input.nextInt();
  
tip1 = billAmount * .10;
tip2 = billAmount * .15;
tip3 = billAmount * .20;
totalAmount1 = billAmount + tip1;
totalAmount2 = billAmount + tip2;
totalAmount3 = billAmount + tip3;
  
System.out.println("Restaurant: " + restaurant);
  
  
System.out.println("Server: " + server);
  
  
System.out.println("Original Bill: " + billAmount);
System.out.println("With 10% tip: " + totalAmount1 + " | Everyone pays: " / );

System.out.println("With 15% tip: " + totalAmount2 + " | Everyone pays: " / );

System.out.println("With 20% tip: " + totalAmount3 + " | Everyone pays: " / );

}
}

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

public class TipCalc
{

    public static void main(String [] args)
    {

        Scanner input = new Scanner(System.in);
        double billAmount;
        int numOfPeople;
        double tip1, tip2, tip3;
        double totalAmount1, totalAmount2, totalAmount3 = 0;


//input
        System.out.print("Which restaurant? ");
        String restaurant = input.next();
        System.out.print("What is your servers name? ");
        String server = input.next();
        System.out.print("What is your bill amount? ");
        billAmount = input.nextDouble();
        System.out.print("How many people in your party? ");
        numOfPeople = input.nextInt();

        tip1 = billAmount * .10;
        tip2 = billAmount * .15;
        tip3 = billAmount * .20;
        totalAmount1 = billAmount + tip1;
        totalAmount2 = billAmount + tip2;
        totalAmount3 = billAmount + tip3;

        System.out.println("Restaurant: " + restaurant);


        System.out.println("Server: " + server);


        System.out.println("Original Bill: " + billAmount);
        System.out.printf("With 10%% tip: %.2f  | Everyone pays: %.2f\n", totalAmount1, (totalAmount1/numOfPeople));
        System.out.printf("With 15%% tip: %.2f  | Everyone pays: %.2f\n", totalAmount2, (totalAmount2/numOfPeople));
        System.out.printf("With 20%% tip: %.2f  | Everyone pays: %.2f\n", totalAmount3, (totalAmount3/numOfPeople));
    }
}

Output:

Which restaurant? TGIFridays What is your servers name? Tony What is your bill amount? 24.13 How many people in your party? 4

Note: Please comment below if you have any doubtsPlease up vote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
1. Need help with a Java application that will compute tip amounts based on user input....
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
  • 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 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...

  • Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895...

    Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895    {        public static void header()        {            System.out.println("\tWelcome to St. Joseph's College");        }        public static void main(String[] args) {            Scanner input = new Scanner(System.in);            int d;            header();            System.out.println("Enter number of items to process");            d = input.nextInt();      ...

  • Java code is calculating the bill wrong and not displaying currency at the end: I've highlighted...

    Java code is calculating the bill wrong and not displaying currency at the end: I've highlighted the error in the cosole Southwest Power and Light Billing Statement Please enter your name > J, P Customer name:J, P Meter reading date > 2/15/16 Meter reading date:2/15/16 Electricity used: > 225 The basic rate is:22.5 The totalBill is 225.0 Calculate another bill? (Y/N)?: The correct answer should be baseline charge: $22.50 and total bill: $22.50 The Charges are based on these: 0kw...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • You will write a single java program called MadLibs. java.

    You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...

  • Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

    Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate. ·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user. ·         The application prompts the user to continue. ·         The program stops prompting the user for values after taking 3 loan amounts. ·         The application calculates and displays the total loan and interest amount and ends the program Example Output Welcome to...

  • Here is everything I have on my codes, the compiler does not allow me to input...

    Here is everything I have on my codes, the compiler does not allow me to input my name, it will print out "Please enter your name: " but totally ignores it and does not allow me to input my name and just proceeds to my result of ID and Sale. Please help. I've bolded the part where it I should be able to input my name package salesperson; public class Salesperson { String Names; int ID; double Sales; // craeting...

  • I am creating a program where a user will enter in a price amount. And then...

    I am creating a program where a user will enter in a price amount. And then the program will determine how many 20, 10, 5, 1, etc.. they get back. I keep getting "error: unexpected type" in my findValue method. Not too sure why I am getting this. There also might be more bugs in there that I am not aware of because it wont compile. Any help is appreciated. Here is my code: import java.util.Scanner; public class prac1 {...

  • Need Java help: 1. Create a Java program that accepts input String input from a user...

    Need Java help: 1. Create a Java program that accepts input String input from a user of first name. 2. Create a Java program that accepts input String input from a user of last name. 3. Concatenate the Strings in a full name variable and print to the console.

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