Java Reference
In-Depth Information
//*********************************
// methods section - constructors
//*********************************
// Fully parameterized constructor for Employee objects
public Employee(String n, String a, String s, int x)
{
this.name = n;
this.address = a;
this.ssn = s;
this.dependants = x;
this.empNum = ++empCounter;
}
// Nonparameterized constructor assigns only an employee number
public Employee()
{
this.empNum = ++empCounter;
}
// Partially parameterized constructor assigns name and
// consecutive employee number
public Employee(String n)
{
this.name = n;
this.empNum = ++empCounter;
}
//*********************************
// methods section - other methods
//*********************************
public void showData()
{
System.out.print("number: " + this.empNum);
System.out.print("\tname: " + this.name);
System.out.print("\t\taddress: " + this.address);
System.out.print("\n\t\tSSN: " + this.ssn);
System.out.print("\t\tdependants: " + this.dependants +
"\n\n");
System.out.flush();
}
// Class method is used to access a class variable without
// an object reference
public static void showTotal()
{
System.out.println("Total employees: " + empCounter);
System.out.println();
}
}
//******************************************
//******************************************
// CLASS PayrollDemo
//******************************************
//******************************************
Search WWH ::




Custom Search