设计优惠证抽象类Discount,包含家庭类型和享受优惠人数两个封装属性,为属性添加setter和getter方法;定义抽象方法返回优惠证可每次消费享受的折扣费用 public abstract double getDiscount(int peopleCount);其中peopleCount为单人享受的折扣减少折扣
时间: 2024-02-03 13:11:44 浏览: 17
以下是Discount抽象类的代码实现:
```java
public abstract class Discount {
private String familyType;
private int peopleCount;
public String getFamilyType() {
return familyType;
}
public void setFamilyType(String familyType) {
this.familyType = familyType;
}
public int getPeopleCount() {
return peopleCount;
}
public void setPeopleCount(int peopleCount) {
this.peopleCount = peopleCount;
}
public abstract double getDiscount(int peopleCount);
}
```
在Discount抽象类中,我们定义了两个封装属性:家庭类型和享受优惠人数,并且为它们添加了setter和getter方法。同时,我们定义了一个抽象方法getDiscount,该方法返回优惠证可每次消费享受的折扣费用,其中peopleCount为单人享受的折扣减少折扣。由于不同的优惠证享受的折扣方式可能不同,因此我们将该方法定义为抽象方法,具体实现则由其子类来完成。