1、
//员工类
public class Employee {
private String name;
private String sex;
private double wage;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public double getWage() {
return wage;
}
public void setWage(double wage) {
this.wage = wage;
}
public Employee(){}
public Employee(String name, String sex, double wage) {
this.name = name;
this.sex = sex;
this.wage = wage;
}
public void showInfo(){
System.out.println("员工姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("薪水:"+wage);
}
}
2、
//商品类
public class Goods {
private double unitPrice;
private int account;
public double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(double unitPrice) {
this.unitPrice = unitPrice;
}
public int getAccount() {
return account;
}
public void setAccount(int account) {
this.account = account;
}
public Goods() {}
public Goods(double unitPrice, int account) {
this.unitPrice = unitPrice;
this.account = account;
}
public double totalPrice(){
return unitPrice*account;
}
}
//VIP价格接口
public interface VipPrice {
double DISCOUNT=0.8;
double reducedPrice();
}
//服装类
public class Clothing extends Goods implements VipPrice {
private String style;
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
@Override
public double reducedPrice() {
return VipPrice.DISCOUNT*totalPrice();
}
public Clothing(){}
public Clothing(double unitPrice, int account,String style) {
super(unitPrice, account);
this.style=style;
}
public void showInfo(){
System.out.println("服装单价:"+getUnitPrice());
System.out.println("数量:"+getAccount());
System.out.println("样式:"+style);
System.out.println("原价:"+totalPrice());
System.out.println("VIP价格:"+reducedPrice());
}
}
//测试类
public class Test {
public static void main(String[] args) {
Clothing c=new Clothing(200,1,"男装");
c.showInfo();
}
}
温馨提示:内容为网友见解,仅供参考