-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscountedPurchase.java
More file actions
33 lines (24 loc) · 1.02 KB
/
DiscountedPurchase.java
File metadata and controls
33 lines (24 loc) · 1.02 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
import java.util.Scanner;
public class DiscountedPurchase {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the quantity of items: ");
int quantity = scanner.nextInt();
System.out.print("Enter the price per item (in Rs.): ");
double pricePerItem = scanner.nextDouble();
double totalExpense = quantity * pricePerItem;
double discount = 0;
if (quantity > 50) {
discount = 0.1; // 10% discount
} else if (quantity >= 25) {
discount = 0.05; // 5% discount
}
double discountedPrice = totalExpense * (1 - discount);
System.out.println("Total expense before discount: Rs. " + totalExpense);
if (discount > 0) {
System.out.println("Discount (" + (discount * 100) + "%): Rs. " + (totalExpense - discountedPrice));
}
System.out.println("Total expense after discount: Rs. " + discountedPrice);
scanner.close();
}
}