1.B
2.AD
题目要求:
某公司要开发内部的 “办公信息化管理系统”,请使用面向对象的思想描述以下员工信息。
任务描述
一、语言和环境
实现语言
Java语言
环境要求及开发工具
JDK、Eclipse
二、程序整体要求
package com.dodoke.lianxi.model;
/**
* 职务类
* @author Administrator
*
*/
public class Post {
private String postNo;//职务编号
private String postName;//职务名称
public String getPostNo() {
return postNo;
}
public void setPostNo(String postNo) {
this.postNo = postNo;
}
public String getPostName() {
return postName;
}
public void setPostName(String postName) {
this.postName = postName;
}
//无参构造器
public Post() {
}
//有参构造器
public Post(String postNo, String postName) {
super();
this.setPostName(postName);
this.setPostNo(postNo);
}
package com.dodoke.lianxi.model;
/**
* 部门类
* @author Administrator
* 通过部门类实例化两种对象-市场部对象,人事部对象
* 市场部员工要通过市场部对象中的数组存储并统计
* 人事部员工要通过市场部对象中的数组存储并统计
*/
public class Department {
private String departmentNo;
private String departmentName;
private Staff[] staffs;//员工数组
private int staffNum;//员工数量
public String getDepartmentNo() {
return departmentNo;
}
public void setDepartmentNo(String departmentNo) {
this.departmentNo = departmentNo;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public Staff[] getStaffs() {
if(this.staffs == null) {
this.staffs = new Staff[6];
}
return staffs;
}
public void setStaffs(Staff[] staffs) {
this.staffs = staffs;
}
public int getStaffNum() {
return staffNum;
}
public void setStaffNum(int staffNum) {
this.staffNum = staffNum;
}
public Department() {
super();
}
public Department(String departmentNo, String departmentName) {
super();
this.departmentNo = departmentNo;
this.departmentName = departmentName;
}
/**
* 统计员工个数
* 先添加,在统计
*/
public void statistic(Staff staff) {
int i;
for(i = 0; i < this.getStaffs().length; i++) {
if(this.getStaffs()[i] == null) {
this.getStaffs()[i] = staff;
break;
}
}
this.staffNum = i + 1;
}
}
package com.dodoke.lianxi.model;
public class Staff {
private String name;
private String no;
private int age;
private String sex;
private Department department;
private Post post;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public int getAge() {
return age;
}
/**
* 限定年龄只能是18
* @param age
*/
public void setAge(int age) {
if(age > 65 || age < 18) {
this.age = 18;
return;
}
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
if(sex.equals("男") || sex.equals("女")) {
this.sex = sex;
} else{
this.sex = "男";
}
}
public Department getDepartment() {
if(this.department == null) {
this.department = new Department();
}
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
public Post getPost() {
if(this.post == null) {
this.post = new Post();
}
return post;
}
public void setPost(Post post) {
this.post = post;
}
public Staff() {
super();
}
public Staff(String name, String no, int age, String sex, Department department, Post post) {
super();
this.name = name;
this.no = no;
this.age = age;
this.sex = sex;
this.department = department;
this.post = post;
}
public String introduction() {
String str = "";
str = "姓名:" + this.getName() + "\n" + "工号:" + this.getNo() + "\n";
str += "性别:" + this.getSex() + "\n" + "年龄:" + this.getAge() + "\n";
str += "职务:" + this.getDepartment().getDepartmentName() + this.getPost().getPostName();
return str;
}
}
package com.dodoke.lianxi.test;
import com.dodoke.lianxi.model.Department;
import com.dodoke.lianxi.model.Post;
import com.dodoke.lianxi.model.Staff;
public class Test {
public static void main(String[] args) {
Department depR = new Department("D001","人事部");
Department depS = new Department("D002","市场部");
Post psjl = new Post("P001","经理");
Post pszl = new Post("P002","助理");
Post pszy = new Post("P003","职员");
Staff one = new Staff("张铭","S001",29,"男",depR,psjl);
Staff two = new Staff("李艾爱","S002",21,"女",depR,pszl);
Staff three = new Staff("孙超","S003",29,"男",depR,pszy);
Staff four = new Staff("张美美","S004",26,"女",depS,pszy);
Staff five = new Staff("蓝迪","S005",37,"男",depS,psjl);
Staff six = new Staff("米莉","S006",24,"女",depS,pszy);
System.out.println(one.introduction());
System.out.println("========================");
System.out.println(two.introduction());
System.out.println("========================");
System.out.println(three.introduction());
System.out.println("========================");
System.out.println(four.introduction());
System.out.println("========================");
System.out.println(five.introduction());
System.out.println("========================");
System.out.println(six.introduction());
System.out.println("========================");
depR.statistic(one);
depR.statistic(two);
depR.statistic(three);
System.out.println("人事部共有" + depR.getStaffNum() + "名员工");
depS.statistic(four);
depS.statistic(five);
depS.statistic(six);
System.out.println("市场部共有" + depS.getStaffNum() + "名员工");
}
}