/** 描述支付方式的抽象类 */
abstract public class Payment {
public Payment() { }
public Payment(BigDecimal amount) {
this.amount = amount;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
private BigDecimal amount;
}
/** 一个扩展了Payment类的子类,描述信用卡支付方式 */
public class CreditCardPayment extends Payment {
public CreditCardPayment() {
}
public CreditCardPayment(BigDecimal amount) {
super(amount);
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
public boolean authorize() {
return false; //暂不实现
}
private String cardNumber;
}
/** 一个扩展了Payment类的子类,描述现金支付方式 */
public class CashPayment extends Payment {
public CashPayment() {
super();
}
public CashPayment(BigDecimal amount) {
super(amount);
}
public BigDecimal getAmountTendered() {
return amountTendered;
}
public void setAmountTendered(BigDecimal amountTendered) {
this.amountTendered = amountTendered;
}
private BigDecimal amountTendered;
public BigDecimal calcChange() {
return amountTendered.subtract(super.getAmount());
}
}
|