01219343/unit/discount

จาก Theory Wiki
รุ่นแก้ไขเมื่อ 16:34, 24 มกราคม 2556 โดย Jittat (คุย | มีส่วนร่วม)
(ต่าง) ←รุ่นแก้ไขก่อนหน้า | รุ่นแก้ไขล่าสุด (ต่าง) | รุ่นแก้ไขถัดไป→ (ต่าง)
ไปยังการนำทาง ไปยังการค้นหา
This exercise is part of 01219343-55.

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;
	}
}