Java Reference
In-Depth Information
/** An instance contains a person's name, year hired, and salary */
public class Employee {
private String name; // Employee's name
private int start; // Year hired
private double salary= 50000; // Salary
/** Constructor: a person with name n , year hired d , salary 50,000 */
public Employee(String n, int d) {
name= n;
start= d;
}
/** = name of this Employee */
public String getName()
{ return name; }
/** Set the name of this Employee to n */
public void setName(String n)
{ name= n; }
/** = year this Employee was hired */
public int getStart()
{ return start; }
/** Set the year this Employee was hired to y */
public void setStart( int y)
{ start= y; }
/** = Employee's total compensation (here, the salary) */
public double getCompensation()
{ return salary; }
/** Change this Employee's salary to d */
public void changeSalary( double d)
{ salary= d; }
/** = String representation of this Employee */
public String toString() {
return getName() + ", year " + getStart() +
", salary " + salary;
}
}
Figure 3.1:
Class Employee
Search WWH ::




Custom Search