-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedLogExercise.java
More file actions
51 lines (49 loc) · 1.96 KB
/
Copy pathNestedLogExercise.java
File metadata and controls
51 lines (49 loc) · 1.96 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
package PackageIntro;
import java.util.Scanner;
public class NestedLogExercise {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to our online shop, please input the current month in number: ");
int month=sc.nextInt();
System.out.println("Nice, now please input the current date: ");
int date=sc.nextInt();
if (month != 8) {
System.out.println("Apologies, this shop only runs in August in commemoration of independence day.");
System.out.println("Have a nice day!");
System.exit(0);
}
System.out.println("Welcome, please input the total purchase you have made: ");
int totalpurchase=sc.nextInt();
int endpurchase = totalpurchase;
if (totalpurchase >= 4500000) {
System.out.println("You have been given a 45% discount");
int fortyfivediscount = (int) (0.45*totalpurchase);
endpurchase = totalpurchase - fortyfivediscount;
}
else if (totalpurchase >= 2000000) {
System.out.println("You have been given a 20% discount");
int twentydiscount = (int) (0.2*totalpurchase);
endpurchase = totalpurchase - twentydiscount;
}
else if (totalpurchase >= 1700000) {
System.out.println("You have been given a 17% discount");
int seventeendiscount = (int) (0.17*totalpurchase);
endpurchase = totalpurchase - seventeendiscount;
}
else if (totalpurchase >= 800000) {
System.out.println("You have been given a 8% discount");
int eightdiscount = (int) (0.08*totalpurchase);
endpurchase = totalpurchase - eightdiscount;
}
else {
System.out.println("You did not get any discount");
}
System.out.println("The price now is " + endpurchase);
if (date == 17) {
System.out.println("Since you are purchasing in the independence day, you have gotten an extra 100k coupon");
endpurchase -= 100000;
System.out.println("After applying the coupon, the price is " + endpurchase);
}
}
// TODO Auto-generated method stub
}