定义一个雇员类 (1)应包含得信息有,雇员得编号,姓名,性别,年龄,所属部门。(2)雇员可以具有得行为有:参加生产活动,领取公资,休息,娱乐。实例化一名雇员,对相关属性和方法进行测试。2怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); }} 如果仔细写呢,很多东西都要考虑到,比如说English的表达上。雇员是Employee所以是public class Employee {}ID那一项,应该是String的,而不是一个int。而且英文应该是 Serial。至少IBM是这样的。而所属部分那里,才应该用int呢,就像你玩数据库的时候,别人的部门不应该用部门那张表里面的ID作为info嘛? 而且我记不得Java有没有unsigned这一说了,年纪这玩意不要出负数才好。性别那里显然应该用int或者Boolean嘛,非男既女。很多大公司的Employee超过10万人的,搞个String进去至于其他的,再说了。 性别那里显然应该用int或者Boolean嘛,非男既女。===============================================太绝对了 ID那一项,应该是String的,而不是一个int???private static int id ;!!! Serial = getId();/* . . . . . */public static int getId(){ Serial = id; id++; return Serial;} 对象序列化能保存静态的成员变量? 关于局域网聊天室 求一句sql 请问如果通过JAVA编程获得无线网卡的RSSI? 本站java FAQ下载 如何用正则表达式判断一个字符串只含英文? 简单问题:大家看看这段代码问题在哪?(接受键盘输入的) 大家都用什么写代码的逻辑结构图和流程图啊? 今天看视频的第一个项目 各种各样的Exception啊 求解 如何写只能产生10个或10个以下对象的类 帮忙看个简单代码 数据类型转换Object->List问题
// 参加生产活动,领取公资,休息,娱乐。实例化一名雇员 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();
}}
Employee
所以是
public class Employee {
}ID那一项,应该是String的,而不是一个int。而且英文应该是 Serial。
至少IBM是这样的。
而所属部分那里,才应该用int呢,就像你玩数据库的时候,别人的部门不应该用部门那张表里面的ID作为info嘛? 而且我记不得Java有没有unsigned这一说了,年纪这玩意不要出负数才好。性别那里显然应该用int或者Boolean嘛,非男既女。
很多大公司的Employee超过10万人的,搞个String进去至于其他的,再说了。
===============================================
太绝对了
. . . . .
*/public static int getId(){
Serial = id;
id++;
return Serial;
}