• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# TipCalculator1

a guest Dec 12th, 2012 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2. This program will use a bill and service rating
3. to compute the tip and total amount as well as
4. divide the entire cost by the number of people
5. in one's party.
6. */
7. import java.util.Scanner;
8.
9. public class TipCalculator1 {
10.         public static void main(String[] args) {
11.                 //Create a scanner
12.                 Scanner input = new Scanner(System.in);
13.
14.                 //Obtain the total bill amount
15.                 System.out.println("Enter bill amount. eg. 37.96: ");
16.                 double totalBill = input.nextDouble();
17.
18.                 //Obtain the service level
19.                 System.out.println("Rate the overall service from 0 to 10: ");
20.                 double serviceRating = input.nextInt();
21.
22.                 //Obtain the number of individuals in your party
23.                 System.out.println("How many people are in your party? ");
24.                 int numberInParty = input.nextInt();
25.
26.                 //Calculate the percentage tip
27.                 double percentageTip = ((serviceRating / 100) + 0.1);
28.
29.                 //Calculate the total bill plus tip
30.                 double billPlusTip = totalBill + totalBill * percentageTip;
31.
32.                 //Calculate how much each individual owes
33.                 double totalOwedByEach = billPlusTip / numberInParty;
34.
35.                 //Print the amount owed by each person
36.                 System.out.println("With a " + (double)percentageTip + "% tip, The total bill came out to " + billPlusTip);
37.                 System.out.println("Each person owes \$" + totalOwedByEach);
38.         }
39. }
RAW Paste Data
Top