java开发实战经典(第二版)P157 5-2

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

package book;

public class JiOu {
	private String number;
	private String name;
	private double salary;
	private double add;

	public double add(double salary, double add) {
		return (salary + salary * add);
	}

	@Override
	public String toString() {

		return "姓名:" + this.name + "\n" + "编号:" + this.number + "\n" + "基本工资:" + this.salary + "\n" + "工资增长度:"
				+ this.add + "\n" + "增长后的工资:" + this.add(this.salary, this.add);
	}

	public JiOu(String number, String name, double salary, double add) {
		this.number = number;
		this.name = name;
		this.salary = salary;
		this.add = add;

	}

	public static void main(String[] args) {
		JiOu employee = new JiOu("111", "SMC", 10000.0, 0.5);
		System.out.println(employee);
	}

}

运行结果为:

姓名:SMC
编号:111
基本工资:10000.0
工资增长度:0.5
增长后的工资:15000.0

 

你可能感兴趣的:(java开发实战经典(第二版))