-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscountSimple.java
More file actions
22 lines (19 loc) · 597 Bytes
/
Copy pathDiscountSimple.java
File metadata and controls
22 lines (19 loc) · 597 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package java_core;
public class DiscountSimple {
public static void main(String args[]) {
double finalPrice;
double totalPrice = 1000;
int discount = 10;
if (totalPrice > 500) {
finalPrice = totalPrice * (1- ((double)discount/100));
System.out.println("Congrats!! you got 10% discount");
System.out.println(finalPrice);
}
else {
finalPrice = totalPrice * (1- ((double)5/100));
}
System.out.println("Total price: " + finalPrice );
//single line alternate code - ternary operator:
System.out.println("new cost: " + (totalPrice > 500 ? totalPrice*0.9 : totalPrice*0.95));
}
}