forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeDiscounts.java
More file actions
61 lines (52 loc) · 1.63 KB
/
CoffeDiscounts.java
File metadata and controls
61 lines (52 loc) · 1.63 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
import java.util.Scanner;
public class CoffeDiscounts
{
public static void main(String[] args)
{
int commute;
int busOrBike;
Scanner scan = new Scanner(System.in);
printHeader();
System.out.print("Please enter the distance of the commute: ------> ");
commute = scan.nextInt();
scan.nextLine();
System.out.println();
System.out.print("Please enter a 1 for bicycle, and a 2 for bus: ->");
busOrBike = scan.nextInt();
scan.nextLine();
System.out.println();
findDiscounts(commute, busOrBike);
}
private static void printHeader()
{
System.out.println("Green Coffee Growers of Antarctica");
System.out.println(" Discount Check Software");
System.out.println("==================================");
System.out.println();
}
private static void findDiscounts(int commute, int busOrBike)
{
String result = "You get-----> ";
if (commute < 21)
result += "a free coffee: ";
if(busOrBike == 1)
{
if ((commute >= 30) && ( commute < 50))
result += "20% discount. ";
else if (commute < 50)
result += "30% discount.";
else
result += "No discount";
}
else if (busOrBike == 2)
{
if ((commute >=35) && (commute < 50))
result += "50% discount.";
else if (commute > 35)
result += "30% discount.";
else
result += "No discount.";
}
System.out.println(result);
}
}