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 閱讀(229)
評論(2) 編輯 收藏