-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaTipCalculator
More file actions
66 lines (58 loc) · 1.39 KB
/
Copy pathJavaTipCalculator
File metadata and controls
66 lines (58 loc) · 1.39 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
55
56
57
58
59
60
61
62
63
64
65
66
package com.egarduno.tipCalculator;
import acm.program.*;
import acm.graphics.*;
import acm.io.*;
/*__________________________________
Emilio Garduno
07/01/2013
Tip Calculator
__________________________________*/
@SuppressWarnings("serial")
public class tipCalculator extends ConsoleProgram {
//CONSTANTS
double sTax = .09; //sales tax
double rTax = .02; //restaurant tax
//VARIABLES
double tipUserInput;
double tipAmount;
double mealPrice;
double salesTax;
double restaurantTax;
double totalDue;
/*____________METHODS____________*/
public void run(){
// .setBounds(from left,from top,width,height)
this.getParent().getParent().setBounds(300,40,400,400);
println ("Enter meal price: ");
mealPrice = readDouble();
println ("Enter a tip percent (10, 15, etc.): ");
tipUserInput = readDouble();
tip();
println ("\nTip amount: " + tipAmount);
taxCalc();
println ("Sales Tax: " + salesTax + "\nRestaurant Tax: " + restaurantTax);
total();
println ("\nTotal with tax: " + totalDue);
}
private void taxCalc(){
if (mealPrice == 0){
sTax = 0;
rTax = 0;
}
else {
salesTax = mealPrice * sTax;
restaurantTax = mealPrice * rTax;
}
}
private void tip(){
if (mealPrice == 0){
tipAmount = 0;
}
else {
tipAmount = mealPrice / tipUserInput;
}
}
private void total(){
totalDue = mealPrice + salesTax + restaurantTax + tipAmount;
}
}