SWT301_-_FA_2024_-_PE1_2961.webp
HongThao85

SWT301_-_FA_2024_-_PE1_2961.webp

3
public class OrderCalculator (
public double calculateTotalPrice (double[] itemPrices, String customerType, boolean isVIP, String discountCode) {
if (itemPrices null || itemPrices.length) {
throw new IllegalArgumentException("No items in the order.");
double totalPrice = 0.0;
for (double price itemPrices) ( if (price <0){
throw new IllegalArgumentException("Iten price must be greater than zero.");
totalPrice price;
double discount = 0.0;
discount 0.20; // 20% discount for VIP customers
} else if (customerType.equalsIgnoreCase("Regular")) {
10
11
12
13
14
15

if (isVIP) (
16
17
18
19
20
21
22
23
24
25
discount 0.05; // 5% discount for regular customers
if (discountCode != null && !discountCode.isEmpty()) {
if (discountCode.equals("SALE10")) {
discount+= 0.10; // Additional 10% discount for SALE10 code
) else if (discountCode.equals("WELCOMES")) ( discount + 0.05; // Additional 5% discount for WELCOMES code
double finalPrice totalPrice (1 discount):
return finalPrice <? finalPrice; // Ensuring price does not go below zero
Sample JUnit Test Class for Completion
The following is a partially completed JUnit test class for the OrderCalculator method.Students are required to complete this class by adding the necessary test cases to achieve full equivalence partitioning, boundary value analysis, and branch coverage for the
calculate TotalPrice method.
35 public class OrderCalculatorTest {
Test (expected IllegalArgumentException.class)
OrderCalculator calculator new OrderCalculator();
calculator.calculateTotalPrice (new double()(), "VIP", false, null); // No itens in order
36
37
38
public void testNoltensInOrder() {
39
40
41
}
42
43
87est
44
public void testVIPCustomerWithNoDiscountCode() {
45
46
OrderCalculator calculator new OrderCalculator();
double total calculator.calculateTotalPrice (new double[] (100, 200), "VIP", true, null); // Branch 1: VIP customer assertEquals (240.0, total, 0.01); // 20% discount
48
Zoom
+ 100%
Close
Chưa có bình luận nào.

Thông tin

Category
SWT301
Thêm bởi
HongThao85
Ngày thêm
Lượt xem
4,960
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Image metadata

Filename
SWT301_-_FA_2024_-_PE1_2961.webp
File size
254.6 KB
Dimensions
1920px x 1000px

Share this media

Back
Bên trên Bottom