链表加雇员部门模型
来源:互联网 发布:云计算图标素材 编辑:程序博客网 时间:2024/05/04 10:25
class Link { // 外部类private int length; // 链表长度private Node root; // 根节点private int foot; // 操作数组的角标private Emp[] retData; // 返回数组private class Node { // 私有内部类private Emp data;private Node next; // 下一个节点public Node(Emp data) {this.data = data;}public void addNode(Node newNode) {if (this.next == null) {this.next = newNode;} else {this.next.addNode(newNode);}}public boolean containNode(Emp data) {if (data.compare(this.data)) { // 如果与当前节点数据相符return true;} else {if (this.next != null) { // 不相符时return this.next.containNode(data);} else {return false;}}}public void removeNode(Node previous, Emp data) {if (this.data.compare(data)) {previous.next = this.next;} else {this.next.removeNode(this.next, data);}}public void toArrayNode() {Link.this.retData[Link.this.foot++] = this.data;if (this.next != null) {this.next.toArrayNode();}}public Emp getNode(int index) {if (Link.this.foot++ == index) {return this.data;} else {return this.next.getNode(index);}}} // end class Nodepublic boolean add(Emp data) {if (data == null) {return false;}Node newNode = new Node(data);if (this.root == null) {this.root = newNode;} else {this.root.addNode(newNode);}length++;return true;}public boolean addAll(Emp[] data) {for (int index = 0; index < data.length; index++) {if (!this.add(data[index])) {return false;}}return true;}public int size() {return length;}public boolean isEmpty() {if (this.root == null) {return false;}return true;// 最简单的一句 return this.length==0;}public boolean contains(Emp data) {if (this.root == null || data == null) {return false;}return this.root.containNode(data);}public void remove(Emp data) {if (!contains(data)) {return;}if (data.equals(this.root.data)) {this.root = this.root.next;} else { // 如果要删除的不是根节点this.root.next.removeNode(this.root, data);}this.length--;}public Emp[] toArray() {if (this.length == 0) {return null;}this.foot = 0;this.retData = new Emp[this.length];this.root.toArrayNode();return this.retData;}public void print() {Emp[] str = toArray();for (int i = 0; i < str.length; i++) {System.out.println(str[i].getEmpInfo());}}public Emp get(int index) {if (index > this.length) {return null;}this.foot = 0;return this.root.getNode(index);}public void clear() {this.root = null;this.length = 0;}}class Dept { // 部门模型private Link emps = new Link();private int deptno;private String dname;private String loc;public Dept() {}public Dept(int deptno, String dname, String loc) {this.deptno = deptno;this.dname = dname;this.loc = loc;}public void setEmps(Link emps) {this.emps = emps;}public Link getEmps() {return this.emps;}public boolean compare(Dept dept) {if (this == dept) {return true;}if (dept == null) {return false;}if (this.deptno == dept.deptno && this.dname.equals(dept.dname)&& this.loc.equals(dept.loc)) {return true;}return false;}public String getDeptInfo() {return "部门编号:" + this.deptno + ",名称:" + this.dname + ",位置:" + this.loc;}}class Emp { //雇员模型private int empno;private String ename;private String job;private double sal;private double comm;private Emp mgr;private Dept dept;public Emp(int empno, String ename, String job, double sal, double comm) {this.empno = empno;this.ename = ename;this.job = job;this.sal = sal;this.comm = comm;}public boolean compare(Emp emp) {if (this == emp) {return true;}if (emp == null) {return false;}if (this.empno == emp.empno && this.ename.equals(emp.ename)&& this.job.equals(emp.job) && this.sal == emp.sal&& this.comm == comm) {return true;}return false;}public void setMgr(Emp mgr) {this.mgr = mgr;}public Emp getMgr() {return this.mgr;}public void setDept(Dept dept) {this.dept = dept;}public Dept getDept() {return this.dept;}public String getEmpInfo() {return "雇员编号:" + this.empno + ",姓名:" + this.ename + ",职位:" + this.job+ ",工资:" + this.sal + ",佣金:" + this.comm;}}public class Test2 {public static void main(String[] args) {Emp ea = new Emp(9527,"TIM","CLEAR",800.0,0.0); //设置雇员Emp eb = new Emp(9528,"RED","MANAGER",2450.0,0.0);Emp ec = new Emp(9529,"SMALLLIGHT","PERSIDENT",5000.0,300.0);Dept dept = new Dept(10, "TEST_DEPT", "SHENZHEN"); //设置部门ea.setMgr(eb); //设置领导eb.setMgr(ec);ea.setDept(dept);eb.setDept(dept);ec.setDept(dept);dept.getEmps().add(ea);dept.getEmps().add(eb);dept.getEmps().add(ec);System.out.println(dept.getDeptInfo());dept.getEmps().print();}}
0 0
- 链表加雇员部门模型
- 查询没有雇员的部门信息
- 查询每个部门最低工资的雇员信息
- 思考题1(雇员、部门、领导)
- 查询每个部门最低工资的雇员信息
- 简单类(练习3)部门,雇员,职位,权限
- 查询出部门名称、部门的员工数、部门的平均工资、部门的最低收入雇员姓名和最高收入雇员的姓名
- 查询出部门名称、部门的员工数、部门的平均工资、部门的最低收入雇员姓名和最高收入雇员的姓名
- 雇员
- 接受用户输入的部门编号,用for循环和游标,打印出此部门所有雇员的所有信息
- 求薪水在部门的平均薪水之上的雇员姓名和及薪水
- 按部门编号从小到大的顺序输出雇员名字、工资以及工资与平均工资的差。
- 部门
- 角色模型:用户、部门、角色、权限、模块的关系模型
- 角色模型:用户、部门、角色、权限、模块的关系模型
- 雇员系统
- 查询出每个雇员的姓名,工资,部门名称,工资在公司的等级及其领导的姓名,领导的工资,以及领导所对应的等级
- 公司雇员管理系统
- Hadoop 2.4.0和YARN的安装过程
- 如何获取代码运行时间
- POI 导入EXCEL2003 和EXCEL2007
- 泛型技巧系列:类型字典和Type Traits
- C++中public、protected及private用法(From MSDN)
- 链表加雇员部门模型
- Win下Eclipse提交Hadoop程序出错:org.apache.hadoop.security.AccessControlException: Permission denied: user=D
- .vimrc配置文档示例
- 树形关系查询, connect by 用法
- 【PostgreSQL】PostgreSQL语法
- C++中static关键字总结(转)
- Google 发布 Android 性能优化典范
- Java实现单链表
- python logging 的一个简单的包装