Question
The problems are based on the following Java code, which is part of a sales system that supports a discount. If you use a different
The problems are based on the following Java code, which is part of a sales system that supports a discount. If you use a different programming language, it is your responsibility for the program translation.
public class Sale {
private static double DISCOUNT_RATE = 0.05;
private Vector itemList = new Vector();
public void addItem(Item item) {
itemList.addElement(item);
}
public double getDiscountRate(){
return DISCOUNT_RATE;
}
public double getDiscount(){
return getSubTotal()*getDiscountRate();
}
public double getSubTotal() {
double subTotal = 0.0;
Enumeration items = itemList.elements(); while (items.hasMoreElements()) { Item theNextItem = (Item)nextElement();
subTotal += theNextItem.getItemTotal();
}
return subTotal;
}
public double getDiscountedSubTotal() {
return getSubTotal() getDiscount();
}
}
Requirements: Clearly describe the ideas of your program design and refactoring. Copy and paste all the source code, test cases, and testing results as screen shots. Comment your code if necessary. Handwriting answers will not be accepted.
Complete the Item class to make the program executable. The instance variables of Item should at least include title, (original) unit price, and quantity. Test the program with appropriate test cases. (10 points)
Update your program to support different discounts for seniors and preferred customers. Retest your program and add appropriate new test cases. Your program must use switch (case) statement(s). (30 points)
Update your program for 2) to support that the seniors discount is only on Tuesday. Retest your program and add appropriate new test cases. Your program must keep the switch (case) statement(s). (30 points)
Refactor your program for 3) to eliminate the switch statement(s), and retest your program. (30 points)
(Extra Credit) Update your program for 4) to handle the new discount policy buy one, get the second (and the rest of the same item) 50% off for certain items. (Bonus: up to 30 points)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started