ผลต่างระหว่างรุ่นของ "01219343/unit/discount"
ไปยังการนำทาง
ไปยังการค้นหา
Jittat (คุย | มีส่วนร่วม) |
Jittat (คุย | มีส่วนร่วม) |
||
แถว 7: | แถว 7: | ||
* For non-member customer: | * For non-member customer: | ||
** If the price is at least 1,000.00 baht, give 7% discount. | ** If the price is at least 1,000.00 baht, give 7% discount. | ||
+ | |||
+ | Develop a static method: | ||
+ | |||
+ | PriceCalculator.calculateDiscount(Customer customer, double price) | ||
+ | |||
+ | that returns the amount of discount a <code>customer</code> should get when the price is <code>price</code> | ||
+ | |||
+ | You should stricly follow the TDD process (write test, watch the test fails, fixe the code, and repeat). | ||
+ | |||
+ | Use the following definition of <code>Customer</code>: | ||
+ | |||
+ | <pre> | ||
+ | public class Customer { | ||
+ | private boolean isMember; | ||
+ | |||
+ | Customer(boolean isMember) { | ||
+ | this.isMember = isMember; | ||
+ | } | ||
+ | |||
+ | public void setMember(boolean isMember) { | ||
+ | this.isMember = isMember; | ||
+ | } | ||
+ | |||
+ | public boolean isMember() { | ||
+ | return isMember; | ||
+ | } | ||
+ | } | ||
+ | </pre> |
รุ่นแก้ไขเมื่อ 07:56, 24 มกราคม 2556
The rules that a shop used to give discounts to customers are as follow.
- If the customer is a member:
- Always give at least 5% discount.
- If the price is at least 1,000.00 baht, give 10% discount.
- If the price is more than 500.00 baht, give 7% discount.
- For non-member customer:
- If the price is at least 1,000.00 baht, give 7% discount.
Develop a static method:
PriceCalculator.calculateDiscount(Customer customer, double price)
that returns the amount of discount a customer
should get when the price is price
You should stricly follow the TDD process (write test, watch the test fails, fixe the code, and repeat).
Use the following definition of Customer
:
public class Customer { private boolean isMember; Customer(boolean isMember) { this.isMember = isMember; } public void setMember(boolean isMember) { this.isMember = isMember; } public boolean isMember() { return isMember; } }