展开全部
参考代码:
class Department {
private String dName;
private static Double dMoney;
private Integer dPeople;
public Department(String dName, Integer dPeople) {
this.dName = dName;
this.dPeople = dPeople;
}
public void consume(double c) {
if (c <= dMoney) {
dMoney = dMoney - c;
} else {
dMoney = 0D;
System.out.println("账户已清零!");
}
}
public String getdName() {
return dName;
}
public void setdName(String dName) {
this.dName = dName;
}
public static Double getdMoney() {
return dMoney;
}
public static void setdMoney(Double dMoney) {
Department.dMoney = dMoney;
}
public Integer getdPeople() {
return dPeople;
}
public void setdPeople(Integer dPeople) {
this.dPeople = dPeople;
}
}
public class Demo {
public static void main(String[] args) {
Department.setdMoney(300D);
Department d1 = new Department("部门1", 20);
Department d2 = new Department("部门2", 10);
d1.consume(80);
d2.consume(40);
System.out.println("剩下的62616964757a686964616fe59b9ee7ad9431333433626438钱:" + Department.getdMoney());
}
}
输出结果:
输出结果