5.20 面向对象案例分析二
class Employee {
private long empno;
private String ename;
private double salary;
private double rate;
public Employee(){}
public Employee(long empno,String ename,double salary,double rate){
this.empno = empno;
this.ename = ename;
this.salary = salary;
this.rate = rate;
}
public double salaryIncValue(){
return this.salary * this.rate;
}
public double salaryIncResult(){
this.salary = this.salary * (1 + this.rate);
return this.salary;
}
public String getInfo(){
return "雇员编号:" + this.empno + ",姓名:" + this.ename + ",薪水:" + this.salary + ",增长率:" + this.rate;
}
}
public class HelloWorld {
public static void main(String[] args){
Employee emp = new Employee(7369L,"史密斯",3000.0,0.3);//7369原本是整型,加上"L"变成了long型
System.out.println(emp.getInfo());
System.out.println("工资调整额度:" + emp.salaryIncValue());
System.out.println("工资调整后金额:" + emp.salaryIncResult());
System.out.println(emp.getInfo());
}
}
相信坚持的力量,日复一日的习惯.