employee.java

来自「卡耐基教程SSD3中所有exercise和quiz的全部答案」· Java 代码 · 共 87 行

JAVA
87
字号
/**
 * This class models an employee. The following information is maintained:
 * <ol>
 * <li>the ID of the employee, an <code>int</code></li>
 * <li>the name of the employee, a <code>String</code></li>
 * <li>the salary of the employee, a <code>double</code></li>
 * </ol>
 *
 * @author  iCarnegie
 * @version  1.0.0
 */
public class  Employee {

	/* The ID of the employee */
	private int id;

	/* The name of the employee */
	private String  name;

	/* The salary of the employee */
	private double  salary;

	/**
	 * Creates an employee object with the specified ID, name and salary.
	 *
	 * @param initialId  the ID of the employee.
	 * @param initialName  the name of the employee.
	 * @param initialSalary  the salary of the employee.
	 */
	public Employee(int initialId, String initialName, double initialSalary) {

		this.id = initialId;
		this.name = initialName;
		this.salary = initialSalary;
	}

	/**
	 * Returns the ID of this employee.
	 *
	 * @return  the ID of this employee.
	 */
	public int  getId()  {

		return  this.id;
	}

	/**
	 * Returns the name of this employee.
	 *
	 * @return  the name of this employee.
	 */
	public String  getName()  {

		return  this.name;
	}

	/**
	 * Returns the salary of this employee.
	 *
	 * @return  the salary of this employee.
	 */
	public double  getSalary()  {

		return  this.salary;
	}

	/**
	 * Modifies the salary of this employee.
	 *
	 * @param newSalary  the new salary of this employee.
	 */
	public void  setSalary(double newSalary)  {

		this.salary = newSalary;
	}

	/**
	 * Returns the string representation of this employee in the following
	 * format: Employee[<i>ID</i>,<i>name</i>,<i>salary</i>]
	 *
	 * @return a string representation of this employee.
	 */
	public String  toString()  {

		return "Employee[" + getId() + "," + getName() + "," + getSalary() +"]";
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?