员工父类
public class Employee {
private String id;
private String name;
private double cunKuan;
private double gongZi;
public Employee() {
}
public Employee(String id, String name, double cunKuan, double gongZi) {
this.id = id;
this.name = name;
this.cunKuan = cunKuan;
this.gongZi = gongZi;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getCunKuan() {
return cunKuan;
}
public void setCunKuan(double cunKuan) {
this.cunKuan = cunKuan;
}
public double getGongZi() {
return gongZi;
}
public void setGongZi(double gongZi) {
this.gongZi = gongZi;
}
}
经理
public class Manager extends Employee{
private double jiangjin;
public Manager() {
}
public Manager(String id, String name, double cunKuan, double gongZi, double jiangjin) {
super(id, name, cunKuan, gongZi);
this.jiangjin = jiangjin;
}
public double getJiangjin() {
return jiangjin;
}
public void setJiangjin(double jiangjin) {
this.jiangjin = jiangjin;
}
}
厨师
public class Cooker extends Employee{
public Cooker() {
}
public Cooker(String id, String name, double cunKuan, double gongZi) {
super(id, name, cunKuan, gongZi);
}
}
服务员
public class Waiter extends Employee{
public Waiter() {
}
public Waiter(String id, String name, double cunKuan, double gongZi) {
super(id, name, cunKuan, gongZi);
}
}
公司
import java.util.ArrayList;
import java.util.Random;
public class Compony {
private double zongZiChan;
ArrayList<Employee> list = new ArrayList<>();
public void show(){
System.out.println("公司总资产:"+zongZiChan);
System.out.println("----------------------");
if(list == null || list.size() == 0){
System.out.println("没有员工");
return;
}
for (int i = 0; i < list.size(); i++) {
Employee e = list.get(i);
System.out.println("员工ID:"+e.getId()+" 姓名:"+e.getName()+" 存款:"+e.getCunKuan()+" 工资:"+e.getGongZi());
if(e instanceof Manager){
Manager m = (Manager)e;
System.out.println("奖金:"+m.getJiangjin());
}
System.out.println("------------------------------");
}
}
public void faGongZi(){
if(list == null || list.size() == 0) {
System.out.println("没有员工,不发工资");
return;
}
for (int i = 0; i < list.size(); i++) {
Employee e = list.get(i);
zongZiChan -= e.getGongZi();
// System.out.println("总资产还剩:"+zongZiChan);
e.setCunKuan(e.getCunKuan() + e.getGongZi());
// System.out.println(e.getName()+"的存款:"+e.getCunKuan());
if (e instanceof Manager) {
Manager m = (Manager) e;
zongZiChan -= m.getJiangjin();
// System.out.println("总资产还剩:"+zongZiChan);
m.setCunKuan(m.getCunKuan() + m.getJiangjin());
// System.out.println(e.getName()+"的存款:"+e.getCunKuan());
}
}
}
public Employee lucky(){
Random r = new Random();
int index = r.nextInt(list.size());
Employee e = list.get(index);
return e;
}
public void tiaoXin(Employee e,double salary){
e.setGongZi(e.getGongZi()+salary);
}
public Compony() {
}
public Compony(double zongZiChan, ArrayList<Employee> list) {
this.zongZiChan = zongZiChan;
this.list = list;
}
public double getZongZiChan() {
return zongZiChan;
}
public void setZongZiChan(double zongZiChan) {
this.zongZiChan = zongZiChan;
}
public ArrayList<Employee> getList() {
return list;
}
public void setList(ArrayList<Employee> list) {
this.list = list;
}
}
test
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
Compony c = new Compony();
c.setZongZiChan(1000000);
ArrayList<Employee> list = new ArrayList<>();
list.add(new Manager("001","张泽妮",20000,20000,10000));
list.add(new Cooker("002","陈梦阳",30000,10000));
list.add(new Waiter("003","程洪瑞",40000,10000));
c.setList(list);
c.show();
System.out.println("------------------------");
c.faGongZi();
System.out.println("----------------------------");
Employee luck = c.lucky();
c.tiaoXin(luck,-5000);
System.out.println("幸运者ID:"+luck.getId()+" 姓名:"+luck.getName()+" 工资是:"+luck.getGongZi());
}
}
2.自己全部写出来了,无难点
3.开心,充实
4.加油,喝点咖啡别犯困.