-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVerifyCommission.java
More file actions
30 lines (25 loc) · 1.22 KB
/
Copy pathVerifyCommission.java
File metadata and controls
30 lines (25 loc) · 1.22 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
import java.math.BigDecimal;
import java.math.RoundingMode;
public class VerifyCommission {
public static void main(String[] args) {
BigDecimal totalSale = new BigDecimal("44000");
BigDecimal commissionRate = new BigDecimal("0.033");
BigDecimal commissionFee = totalSale.multiply(commissionRate)
.setScale(0, RoundingMode.HALF_UP);
System.out.println("Total Sale: " + totalSale);
System.out.println("Commission Rate: 3.3%");
System.out.println("Calculated Commission: " + commissionFee);
// Expected: 44000 * 0.033 = 1452
if (commissionFee.compareTo(new BigDecimal("1452")) == 0) {
System.out.println("SUCCESS: Commission calculation is correct.");
} else {
System.out.println("FAILURE: Commission calculation is incorrect.");
}
// Test with a non-integer result
BigDecimal totalSale2 = new BigDecimal("10000");
BigDecimal commissionFee2 = totalSale2.multiply(commissionRate).setScale(0, RoundingMode.HALF_UP);
System.out.println("\nTotal Sale: " + totalSale2);
System.out.println("Calculated Commission (rounded): " + commissionFee2);
// 10000 * 0.033 = 330.00
}
}