Repository navigation
Expand file tree
/
Copy pathCalculateDinner.java
More file actions
54 lines (41 loc) · 1.49 KB
/
Copy pathCalculateDinner.java
File metadata and controls
54 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
import java.text.DecimalFormat;
public class CalculateDinner {
public static void main(String[] args) {
// User inputs dinner pricing information, program outputs total and change
// required
DecimalFormat df = new DecimalFormat("$#,###,###,###,###,###.00");
Scanner sc = new Scanner(System.in);
// Prompt user for costs
System.out.print("How much did your dinner cost? ");
double dinner = sc.nextDouble();
System.out.print("How much did your drink cost? ");
double drink = sc.nextDouble();
System.out.print("How much did your dessert cost? ");
double dessert = sc.nextDouble();
System.out.println("");
// Current total meal cost
double cost = dinner + drink + dessert;
System.out.println("Meal Cost: " + df.format(cost));
// Tax
double tax = cost * .06625;
System.out.println("Tax: " + df.format(tax));
// Tip
double withTax = cost + tax;
double tip = withTax * .20;
System.out.println("Added Tip: " + df.format(tip));
// Round tip
double tipRounded = Math.round(tip);
System.out.println("Rounded Tip: " + df.format(tipRounded));
System.out.println("---------------");
// Final cost
double totalCost = cost + tax + tipRounded;
System.out.println("Total: " + df.format(totalCost));
// Prompt user for how much they paid and find change
System.out.print("How much did you pay? ");
int payment = sc.nextInt();
sc.close();
double change = payment - totalCost;
System.out.print("Your change is: " + df.format(change));
}
}