• 员工表及员工部门表的简单java类


    今天课上学习了简单java类的学习 

    现将自己练习的员工表及员工部门表的简单java类整理如下 

    员工类

    public class Semp {
    //定义私有属性
    private int sid;
    private String firstname;
    private String title;
    private Dept deptid;
    private double salary;
    //无参构造
    public Semp(){

    }
    public Semp(int sid,String firstname,String title,double salary){
    this.sid=sid;
    this.firstname=firstname;
    this.title=title;
    this.salary=salary;
    }
    //设置setter getter方法
    public void setSid(int sid){
    this.sid=sid;
    }
    public int getSid(){
    return this.sid;
    }
    public void setFirstname(String firstname){
    this.firstname=firstname;
    }
    public String getFirstname(){
    return this.firstname;
    }
    public void setTitle(String title){
    this.title=title;
    }
    public String getTitle(){
    return this.title;
    }
    public void setDeptid(Dept deptid){
    this.deptid=deptid;
    }
    public Dept getDeptid(){
    return this.deptid;
    }
    public void setSalary(double salary){
    this.salary=salary;
    }
    public double getSalary(){
    return this.salary;
    }
    //获得所有属性的方法
    public String getInfo(){
    return "员工编号"+this.sid+",姓氏"+this.firstname+",职位"+this.title+",工资"+this.salary;
    }
    }

    部门类

    class Dept{
    private Semp[] id;
    private String deptname;
    private int rid;
    public Dept(){

    }
    public Dept(String deptname,int rid){
    this.deptname=deptname;
    this.rid=rid;
    }
    public void setId(Semp[] id){
    this.id=id;
    }
    public Semp[] getId(){
    return this.id;
    }
    public String getDeptname(){
    return this.deptname;
    }
    public int getRid(){
    return this.rid;
    }
    public boolean Compare(Dept dept){
    if(dept==null){
    return false;
    }
    if(this==dept){
    return true;
    }
    if(this.rid==dept.rid && this.getDeptname().equals(dept.getDeptname())){
    return true;
    }
    return false;
    }
    public String getInfo(){
    return "部门名称"+deptname+",部门地址编号"+rid;
    }
    }

    测试主类

    public class Test {

    public static void main(String[] args) {
    Semp semp1 = new Semp(1001,"张三","销售员",2500);
    Semp semp2 = new Semp(1002,"李四","运营助理",4000);
    Semp semp3 = new Semp(1003,"王五","销售员",3000);
    Dept dept1 = new Dept("销售部",01);
    Dept dept2 = new Dept("运营部",02);
    semp1.setDeptid(dept1);
    semp2.setDeptid(dept2);
    semp3.setDeptid(dept1);
    dept1.setId(new Semp[]{semp1,semp3});
    dept2.setId(new Semp[]{semp2});
    System.out.println(dept1.getInfo());
    System.out.println(semp2.getDeptid().getInfo());
    for(int i=0;i<dept1.getId().length;i++){
    System.out.println(dept1.getId()[i].getInfo());
    }
    boolean b = dept1.Compare(dept2);
    System.out.println(b);



    }

    }

  • 相关阅读:
    Hello China最新开发进展
    虚拟软驱影像文件制作程序下载路径:http://download.csdn.net/source/738137
    Swing透明和变换
    利用Java存储过程简化数据库操作
    Hello China V1.5 源码下载地址
    防止程序重复执行的单元
    判断文件大小的函数
    TMainMenu 隐藏与显示菜单
    最简单的Delphi程序(控制台)
    测试代码
  • 原文地址:https://www.cnblogs.com/qianqian528/p/7929038.html
Copyright © 2020-2023  润新知