(1)应包含得信息有,雇员得编号,姓名,性别,年龄,所属部门。(2)雇员可以具有得行为有:参加生产活动,领取公资,休息,娱乐。实例化一名雇员,对相关属性和方法进行测试。2怎么做?

解决方案 »

  1.   

    public class Employe { // 雇员得编号,姓名,性别,年龄,所属部门
    // 参加生产活动,领取公资,休息,娱乐。实例化一名雇员 public int id;// 编号 public String name; // 姓名 public String sex = "M";// 性别 M为男 F为女 public int age; // 年龄 public String department; // 所属部门 // 无参构造函数 public Employe() {
    super();
    // TODO Auto-generated constructor stub
    } // 构造函数
    public Employe(int id, String name, String sex, int age, String department) {
    super();
    // TODO Auto-generated constructor stub
    this.id = id;
    this.name = name;
    this.sex = sex;
    this.age = age;
    this.department = department; System.out.println("员工" + this.name + " 被实例化");
    } // 领工资
    public void getSalary() { System.out.println(this.name + "  领取工资");
    } // 休息
    public void relax() { System.out.println(this.name + "  休息");
    } // 娱乐
    public void fun() { System.out.println(this.name + "  娱乐");
    } /**
     * 测试方法
     */
    public static void main(String[] args) {
    //实例化一个员工
    Employe employee = new Employe(1, "ronny", "F", 25, "Tech");
    //领工资
    employee.getSalary();
    //休息
    employee.relax();
    //娱乐
    employee.fun();
    }}
      

  2.   

    如果仔细写呢,很多东西都要考虑到,比如说English的表达上。雇员是
    Employee
    所以是
    public class Employee {
    }ID那一项,应该是String的,而不是一个int。而且英文应该是 Serial。
    至少IBM是这样的。
    而所属部分那里,才应该用int呢,就像你玩数据库的时候,别人的部门不应该用部门那张表里面的ID作为info嘛? 而且我记不得Java有没有unsigned这一说了,年纪这玩意不要出负数才好。性别那里显然应该用int或者Boolean嘛,非男既女。
    很多大公司的Employee超过10万人的,搞个String进去至于其他的,再说了。
      

  3.   

    性别那里显然应该用int或者Boolean嘛,非男既女。
    ===============================================
    太绝对了
      

  4.   

    ID那一项,应该是String的,而不是一个int???private static int id ;!!!
      

  5.   

    Serial = getId();/*
     . . . . .  
    */public static int getId(){
       Serial = id;
       id++;
      return Serial;
    }