package com.dodoke.stu_manager.bean;
/**
* 职务类
* @author user
*
*/
public class Position {
//职务成员属性:职务编号;部分名称;
private String posNum;
private String posName;
//创建成员属性get与set方法
public String getPosNum() {
return posNum;
}
public void setPosNum(String posNum) {
this.posNum = posNum;
}
public String getPosName() {
return posName;
}
public void setPosName(String posName) {
this.posName = posName;
}
//无参构造器
public Position(){
}
//多参构造器
public Position(String posNum, String posName) {
super();
this.setPosNum(posNum);
this.setPosName(posName);
}
/**
* 描述部门信息方法
* @return
*/
public String info(){
//字符串的拼接,尽量不要写成一长串的形式,会让人看得难受
String str ="职务编号:" + this.posNum + "\n";
str += "部门名称:" + this.posName;
return str;
}
}
package com.dodoke.stu_manager.bean;
/**
* 部门编号
* @author user
*
*/
public class Department {
//成员属性:部门编号;部门名称;员工数组;
private String depNum;
private String depName;
private String[] staffs;
private int studentNum;
//编写成员属性get与set方法
public String getDepNum() {
return depNum;
}
public void setDepNum(String depNum) {
this.depNum = depNum;
}
public String getDepName() {
return depName;
}
public void setDepName(String depName) {
this.depName = depName;
}
public String[] getStaffs() {
if(this.staffs == null){
this.staffs = new String[3];
}
return staffs;
}
public void setStaffs(String[] staffs) {
this.staffs = staffs;
}
public int getStudentNum() {
return studentNum;
}
public void setStudentNum(int studentNum) {
if(studentNum < 0) {
this.studentNum = 0;
return;//这里使用同样使用return终结方法的运行
}
this.studentNum = studentNum;
}
public Department(){
}
public Department(String depNum, String depName) {
super();
this.setDepNum(depNum);
this.setDepName(depName);
}
public Department(String depNum, String depName , String[] staffs) {
super();
this.setDepNum(depNum);
this.setDepName(depName);
this.setStaffs(staffs);
}
public String inat(){
//字符串的拼接,尽量不要写成一长串的形式,会让人看得难受
String str = "部门编号:" + this.getDepNum() + "\n";
str += "部门名称:" + this.getDepName() + "\n";
return str;
}
public void addString(String sta){
int i;
for(i = 0 ; i < this.getStaffs().length; i++){
if(this.getStaffs()[i] == null){
this.getStaffs()[i] = sta;
break;
}
}
this.setStudentNum(i + 1);
}
}
package com.dodoke.stu_manager.bean;
/**
* 员工类
* @author user
*
*/
public class People {
//成员属性:姓名;工号;性别;年龄;所属部门;职务信息
private String peName;
private String peNum;
private String peSex;
private int peAge;
//添加get和set方法
public String getPeName() {
return peName;
}
public void setPeName(String peName) {
this.peName = peName;
}
public String getPeNum() {
return peNum;
}
public void setPeNum(String peNum) {
this.peNum = peNum;
}
public String getPeSex() {
return peSex;
}
public void setPeSex(String peSex) {
//String类的equal()方法,用于判断两个String对象值是否相同,相同返回true,不相同则返回false
if(peSex.equals("男") || peSex.equals("女")){
this.peSex = peSex;
} else {
this.peSex = "男";
}
}
public int getPeAge() {
return peAge;
}
public void setPeAge(int peAge) {
if(peAge > 18 || peAge < 65){
this.peAge = 18;
return;
}
this.peAge = peAge;
}
//无参构造器
public People(){
}
//多参构造器
public People(String peName, String peNum, String peSex, int peAge) {
super();
this.peName = peName;
this.peNum = peNum;
this.peSex = peSex;
this.peAge = peAge;
}
public String inup(){
String app = "姓名:" + this.peName + "\n";
app += "工号:" + this.peNum + "\n";
app += "性别:" + this.peSex + "\n";
app += "年龄:" + this.peAge + "\n";
return app;
}
public String inup(String depName ,String posName){
String app = "姓名:" + this.peName + "\n";
app += "工号:" + this.peNum + "\n";
app += "性别:" + this.peSex + "\n";
app += "年龄:" + this.peAge + "\n";
app += "职务:" + depName + posName;
return app;
}
}
package com.dodoke.stu_manager.test;
import com.dodoke.stu_manager.bean.Department;
import com.dodoke.stu_manager.bean.People;
import com.dodoke.stu_manager.bean.Position;
public class Test1 {
public static void main(String[] args) {
Department dep0 = new Department("D001","人事部");
System.out.println(dep0.inat());
Department dep1 = new Department("D002","市场部");
System.out.println(dep1.inat());
dep0.addString("张铭");
dep0.addString("李艾爱");
dep0.addString("孙超");
dep1.addString("张美美");
dep1.addString("蓝迪");
dep1.addString("米莉");
System.out.println("======================================");
Position position0 = new Position("P001","经理");
System.out.println(position0.info());
Position position1 = new Position("P002","助理");
System.out.println(position1.info());
Position position2 = new Position("P003","职员");
System.out.println(position2.info());
System.out.println("======================================");
People people0 = new People("张铭","S001","男",29);
System.out.println(people0.inup(dep0.getDepName(),position0.getPosName()));
System.out.println("======================================");
People people1 = new People("李艾爱","S002","女",21);
System.out.println(people1.inup(dep0.getDepName(),position1.getPosName()));
System.out.println("======================================");
People people3 = new People("孙超","S003","男",29);
System.out.println(people3.inup(dep0.getDepName(),position2.getPosName()));
System.out.println("======================================");
People people4 = new People("张美美","S004","女",26);
System.out.println(people4.inup(dep1.getDepName(),position2.getPosName()));
System.out.println("======================================");
People people5 = new People("蓝迪","S005","男",37);
System.out.println(people5.inup(dep1.getDepName(),position0.getPosName()));
System.out.println("======================================");
People people6 = new People("米莉","S006","女",24);
System.out.println(people6.inup(dep1.getDepName(),position2.getPosName()));
System.out.println("======================================");
System.out.println(dep0.getDepName() + "总共有" + dep0.getStudentNum() + "名员工");
System.out.println(dep1.getDepName() + "总共有" + dep0.getStudentNum() + "名员工");
}
}