-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS3.java
32 lines (29 loc) · 1023 Bytes
/
S3.java
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
package javaPackage;
import java.util.Scanner;
public class S3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter cost price: ");
double costPrice = scanner.nextDouble();
System.out.print("Are you a student? (Y/N): ");
String userInput = scanner.next();
boolean isStudent = userInput.equalsIgnoreCase("Y");
double discount;
if (isStudent) {
if (costPrice > 500) {
discount = 0.1 * costPrice;
} else {
discount = 0.05 * costPrice;
}
} else {
if (costPrice > 500) {
discount = 0.08 * costPrice;
} else {
discount = 0.02 * costPrice;
}
}
double finalPrice = costPrice - discount;
System.out.printf("Discount: %.2f\n", discount);
System.out.printf("Final Price: %.2f\n", finalPrice);
}
}