A,单参数:只传递姓名,则员工号和部门为未知,薪水为0.
B,双参数:传递姓名和员工号,则部门为后勤部,薪水为1000.
C,四参数:传递姓名、员工号、部门、薪水.
D,无参数:则均为空.
显示信息.
Employee
class Employ {
private String name;
private String num;
private float salary;
private String department;
public String getName() {
return name;
}
public void setName(String na) {
this.name = na;
}
public String getNum() {
return num;
}
public void setNum(String n) {
this.num = n;
}
public float getSalary() {
return salary;
}
public void setSalary(float s) {
if(s>0){
this.salary = s;
}
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public static void Emp(){
}
public void pmsg(){
System.out.println("\n"+"员工信息:");
System.out.println("姓 名:"+name);
System.out.println("员工号:"+num);
System.out.println("薪 水:"+salary);
System.out.println("部 门:"+department);
}
public Employ(String n){
this.name=n;
this.num="未知";
this.salary=0.0f;
this.department="未知";
}
public Employ(String n,String nu){
this.name=n;
this.num=nu;
this.salary=1000.0f;
this.department="开发部";
}
public Employ(String n, String nu, float s, String d){
this.name=n;
this.num=nu;
this.salary=s;
this.department=d;
}
public Employ(){
this.name="";
this.num="";
this.salary=0.0f;
this.department="";
}
}
public class Employee{
public static void main(String[] args){
Employ e1=new Employ("张三","E001",888,"后勤部");
Employ e2=new Employ("李四","E002");
Employ e3=new Employ();
Employ e4=new Employ("王五");
e1.pmsg();
e2.pmsg();
e3.pmsg();
e4.pmsg();
}
}
posted on 2010-10-15 22:16
Mineralwasser 阅读(227)
评论(2) 编辑 收藏