Top
Previous Next
Java's Object Orientation, I/O CS 161 - Java

Employee.java

Source: examples/Employee.java



/** A class that encapsulates information about and messages to
** send to Employee objects.
**/
public class Employee {
 
public static void main (String [] args) {
// create a single instance of the Employee class,
Employee anEmp = new Employee("Joe Student");
 
// assign a name and a salary value (any value), using the constructor
// and the setSalary() methods
anEmp.setSalary(50000.);
 
// Access the current salary value (using the getSalary() method)
double current = anEmp.getSalary();
 
// and increase the Employee's salary by 10% using the
// setSalary method again.
current = current + (current * .1);
anEmp.setSalary(current);
 
// then have the Employee object identify itself and it's
// current salary value.
System.out.println(anEmp);
}
 
private String name;
private double salary;
private Employee boss;
 
/** a public constructor for the class that will insure that Employee
objects always have a name field
**/
public Employee( String empName) {
name = empName;
}
 
public String getName() {
return name;
}
 
/** a method to set an Employee object's salary field
**/
public void setSalary( double value ) {
salary = value;
}
 
/** a method to get an Employee object's current salary field value
**/
public double getSalary( ) {
return salary;
}
 
/** a method to set an Employee object's field referencing another
Employee object
**/
public void setBoss ( Employee boss ) {
this.boss = boss;
}
 
/** a method to return a String identifying the field contents of an
Employee
**/
public String toString() {
return name + " salary:" + salary;
}
}

employees.dat

Source: examples/employees.dat



Bill Clinton
200000
Bill Gates
2000000000
Jack Edelman
700000
Susan Koniak
88500
Sally Saltzberg
78900
Bonnie Nagel
32500
Lena Baisayev
540500
Joe Maio
58000
Craig Seymour
125800
Charles Dutton
245000
Jack Trescott
23900
Justin Blum
93700
Daniel Williams
67700
Richard Frank
90000
Kwabena Nimarko
11800


Top
Previous Next
jwd