/**
* 编写一个公司员工类:
成员变量:员工号、姓名、薪水、部门。
成员方法:
a.利用构造方法完成设置信息:
•单参,只传递员工号,则员工姓名:无名氏,薪水:0,部门:未定。
•双参,传递员工号,姓名,则员工薪水为1000,部门:后勤。
•4参,传递员工号,姓名,薪水,部门。
•无参,则均为空值。
b.显示相关信息输出。
* @author SIN
*
*/
public class Employee {
private String id;
private String name;
private double salary;
private String department;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
/**
* 无参构造函数
*/
public Employee() {
}
/**
* 带一个参数的构造函数
* 单参,只传递员工号,则员工姓名:无名氏,薪水:0,部门:未定。
* @param id
*/
public Employee(String id) {
this.id = id;
this.name = "无名氏";
this.salary = 0;
this.department = "未定";
}
/**
* @param id
* @param name
* 双参,传递员工号,姓名,则员工薪水为1000,部门:后勤。
*/
public Employee(String id, String name) {
this.id = id;
this.name = "name";
this.salary = 1000;
this.department = "后勤";
}
/**
*
* @param id
* @param name
* @param salary
* @param depatment
* 4参,传递员工号,姓名,薪水,部门。
*/
public Employee(String id, String name, double salary, String depatment) {
this.id = name;
this.name = name;
this.salary = salary;
this.department = depatment;
}
public static void main(String[] args) {
Employee employee1 = new Employee();
System.out.println("id:" + employee1.getId());
System.out.println("name:" + employee1.getName());
System.out.println("===================");
Employee employee9527 = new Employee("NO.9527");
System.out.println("employee9527's id:" + employee9527.getId());
System.out.println("employee9527's name:" + employee9527.getName());
System.out.println("employee9527's salay:" + employee9527.getSalary());
System.out.println("employee9527's department:" + employee9527.getDepartment());
System.out.println("===================");
Employee employeeJack = new Employee("No.200", "Jack");
System.out.println("employeeJack's id:" + employeeJack.getId());
System.out.println("employeeJack's name:" + employeeJack.getName());
System.out.println("employeeJack's salay:" + employeeJack.getSalary());
System.out.println("employeeJack's department:" + employeeJack.getDepartment());
System.out.println("===================");
Employee employee2 = new Employee("No.366", "Linda", 5600, "保卫处");
System.out.println("employee2's id:" + employeeJack.getId());
System.out.println("employee2's name:" + employeeJack.getName());
System.out.println("employee2's salay:" + employeeJack.getSalary());
System.out.println("employee2's department:" + employeeJack.getDepartment());
}
}
=======
运行结果:
id:null
name:null
===================
employee9527's id:NO.9527
employee9527's name:无名氏
employee9527's salay:0.0
employee9527's department:未定
===================
employeeJack's id:No.200
employeeJack's name:name
employeeJack's salay:1000.0
employeeJack's department:后勤
===================
employee2's id:No.200
employee2's name:name
employee2's salay:1000.0
employee2's department:后勤
public class CompanyPersonnel {
private long number;
private String name;
private float wages;
private String org;
public CompanyPersonnel(long number,String name,float wages,String org){
this.name=name;
this.number=number;
this.org=org;
this.wages=wages;
}
public CompanyPersonnel(long number){
this.number=number;
this.name="无名氏";
this.org="未定";
this.wages=0;
}
public CompanyPersonnel(long number,String name){
this.name=name;
this.number=number;
this.wages=1000;
this.org="后勤";
}
public CompanyPersonnel(){}
@Override
public String toString() {
String s="员工姓名为"+name+"工号为"+number+"薪水为"+wages+"部门为"+org ;
return s;
}
public long getNumber() {
return number;
}
public void setNumber(long number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getWages() {
return wages;
}
public void setWages(float wages) {
this.wages = wages;
}
public String getOrg() {
return org;
}
public void setOrg(String org) {
this.org = org;
}
}
如有疑问,可以HI我,我在线