멤버십 시나리오

회사에서 고객 정보를 활용한 맞춤 서비스를 하기 위해 일반고객(Customer)과
이보다 충성도가 높은 우수고객(VIPCustomer)에 따른 서비스를 제공하고자 함

물품을 구매할 떄 적용되는 할인율과 적립되는 보너스 포인트의 비율이 다름
여러 멤버십에 대한 각각 다양한 서비스를 제공할 수 있음
멤버십에 대한 구현을 클래스 상속을 활용하여 구현해보기

일반 고객 (Customer) 클래스 구현

고객의 속성: 고객 아이디, 고객 이름, 보너스 포인트, 보너스 포인트 적립 비용

일반 고객의 경우 물품 구매 시 1%의 보너스 포인트 적립

package ch03;

public class Customer {
	protected int customerID; //하위 클래스에선 접근 가능하지만 외부 클래스는 접근 불가
	protected String customerName;
	protected String customerGrade;
	int bonusPoint; //package default ->다른 package에서 접근 불가
	double bonusRatio;
	
	public Customer() {
		
		customerGrade="SILVER";
		bonusRatio=0.01;
	}
	public int clacPrice(int price) {
		bonusPoint+=price*bonusRatio;
		return price;
	}
	public String showCustomerInfo() {
		return customerName+"님의 등급은 "+customerGrade+"이며 보너스포인트는 " + bonusPoint+"입니다.";
	}
	public int getCustomerID() {
		return customerID;
	}
	public void setCustomerID(int customerID) {
		this.customerID = customerID;
	}
	public String getCustomerName() {
		return customerName;
	}
	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}
	public String getCustomerGrade() {
		return customerGrade;
	}
	public void setCustomerGrade(String customerGrade) {
		this.customerGrade = customerGrade;
	}
	

}

우수 고객 구현(VIP Customer)

매출에 더 많은 기여를 하는 단골 고객

제품을 살 때 10% 할인해 줌

보너스 포인트는 제품 가격의 5%를 적립해줌

담당 전문 상담원이 배정됨

이미 Customer에 구현된 내용이 중복되므로 Customer을 확장하여 구현함(상속)

 

package ch03;

public class VIPCustomer extends Customer {
	
	double salesRatio;
	String agentID;
	
	public VIPCustomer() {
		bonusRatio=0.05;
		salesRatio=0.1;
		customerGrade="VIP";
	}
}
package ch03;

public class CustomerTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Customer customerLee= new Customer();
		customerLee.setCustomerName("이순신");
		customerLee.setCustomerID(10010);
		customerLee.bonusPoint=1000;
		System.out.println(customerLee.showCustomerInfo());
		
		VIPCustomer customerKim = new VIPCustomer();
		customerKim.setCustomerName("김유신");
		customerKim.setCustomerID(10020);
		customerKim.bonusPoint=10000;
		System.out.println(customerKim.showCustomerInfo());
	}

}

+ Recent posts