MyException - 我的异常网
当前位置:我的异常网» J2SE » 定义并测试一个代表职员的Employee类。员工属性包括

定义并测试一个代表职员的Employee类。员工属性包括“编号”,“姓名”,“基本薪水”,“薪水增长额”,还包括计算薪水增长额以及计算增长后的工资总额的操作方法

www.MyException.Cn  网友分享于:2013-12-14  浏览:694次
定义并测试一个代表员工的Employee类。员工属性包括“编号”,“姓名”,“基本薪水”,“薪水增长额”,还包括计算薪水增长额以及计算增长后的工资总额的操作方法
求高手 给予 程序案例!

------解决方案--------------------

public class Employee {

private int id;
private String name;
private double salary;
private double byPercent;

public Employee(int id,String name,double salary,double byPercent){
this.id = id;
this.name = name;
this.salary = salary;
this.byPercent = byPercent;
}

public int getId(){
return id;
}

public void setId(int 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 double getByPercent() {
return byPercent;
}


public void setByPercent(double byPercent) {
this.byPercent = byPercent;
}

public double raiseSalary(){

return salary += salary * byPercent/100;
}

public static void main(String[] args) {
Employee e1 = new Employee(00001,"张三",1500,20);
Employee e2 = new Employee(00002,"李四",2000,30);

System.out.println("编号"+" "+"员工"+" "+"基本工资"+" "+"增长率%"+" "+"总额");
System.out.println(e1.getId()+" "+e1.getName()+" "
+e1.getSalary()+" "+e1.getByPercent()+" "+ e1.raiseSalary());
System.out.println(e2.getId()+" "+e2.getName()+" "
+e2.getSalary()+" "+e2.getByPercent()+" "+ e2.raiseSalary());
}

}

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有