package com.student.massage;
public class company {
//定义部门信息
private String branch;
private staff[] staffinfo;
private int dutynum;
//创建一个带参构造方法
public company(String branch){
this.setBranch(branch);
}
//从外部获取部门、以及返回部门信息
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
public staff[] getStaffinfo() {
if(this.staffinfo==null)
this.staffinfo=new staff[200];
return staffinfo;
}
public void setStaffinfo(staff[] staffinfo) {
this.staffinfo = staffinfo;
}
public int getDutynum() {
return dutynum;
}
public void setDutynum(int dutynum) {
this.dutynum = dutynum;
}
public void addduty(staff dep){
int i,j;
for(i=0;i<this.getStaffinfo().length;i++){
if(this.getStaffinfo()[i]==null){
this.getStaffinfo()[i]=dep;
if(this.getStaffinfo()[i].getDep().getBranch()=="人事部")
this.dutynum=i+1;
break;
}
}
}
}
package com.student.massage;
public class staff {
//定义员工姓名,工号,性别,年龄,职务
private String name;
private String num;
private String sex;
private int age;
private String duty;
private company Dep;
//创建构造方法
public staff(String name,String num,String sex,int age,String duty,company Dep){
this.setName(name);
this.setNum(num);
this.setSex(sex);
this.setAge(age);
this.setDuty(duty);
this.setDep(Dep);
}
//从外部依次输入,返回员工信息
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
//引入部门
public company getDep() {
return Dep;
}
public void setDep(company dep) {
Dep = dep;
}
public String str(){
String str="姓名:"+this.getName()+"\n工号:"+this.getNum()+"\n性别:"+this.getSex()+"\n年龄:"+this.getAge()+"\n职务:"+this.getDep().getBranch()+this.getDuty();
return str;
}
}
package com.student.massage.test;
import com.student.massage.*;
public class cstest {
public static void main(String[] args) {
//创建方法,输入部门信息
company dep1=new company("人事部");
company dep2=new company("市场部");
//创建方法,输入员工信息
staff staffinfo1=new staff("张铭","S001","男",29,"经理",dep1);
System.out.println(staffinfo1.str());
System.out.println("========================");
staff staffinfo2=new staff("李艾爱","S002","女",21,"助理",dep1);
System.out.println(staffinfo2.str());
System.out.println("========================");
staff staffinfo3=new staff("孙超","S003","男",29,"职员",dep1);
System.out.println(staffinfo3.str());
System.out.println("========================");
staff staffinfo4=new staff("张美美","S004","女",26,"职员",dep2);
System.out.println(staffinfo4.str());
System.out.println("========================");
staff staffinfo5=new staff("蓝迪","S005","男",37,"助理",dep2);
System.out.println(staffinfo5.str());
System.out.println("========================");
staff staffinfo6=new staff("米莉","S006","女",24,"职员",dep2);
System.out.println(staffinfo6.str());
System.out.println("========================");
dep1.addduty(staffinfo1);
dep1.addduty(staffinfo2);
dep1.addduty(staffinfo3);
dep1.addduty(staffinfo4);
dep1.addduty(staffinfo5);
dep1.addduty(staffinfo6);
System.out.println(dep1.getBranch()+"共有员工"+dep1.getDutynum()+"人");
System.out.println(dep2.getBranch()+"共有员工"+dep2.getDutynum()+"人");
}
}
我家小萨叫馒头
相关分类