Java Reference
In-Depth Information
}
public double computePay()
{
return salary/52;
}
}
I want you to save the file in a new empty folder on your hard drive named
c:\payroll (assuming that you are using your c: drive). Be sure to name the file
Employee.java.
Step 2: Compile the Employee Class
Open a command prompt window, change directories to the c:\payroll folder,
and compile Employee.java, as shown in Figure 4.1.
You should now see the bytecode file Employee.class in the c:\payroll
folder.
Step 3: Write the EmployeeDemo Class
You will now write a second class that instantiates and uses Employee objects.
Using your text editor, type in the following EmployeeDemo class.
public class EmployeeDemo
{
public static void main(String [] args)
{
Employee e1, e2;
e1 = new Employee();
e2 = new Employee();
e1.name = “Robert Smith”;
e1.address = “123 Main St., Anytown, USA”;
e1.number = 101;
e1.SSN = 111223333;
e1.salary = 10000.00;
System.out.println(e1.computePay());
e1.mailCheck();
e2.name = “Jane Smith”;
e2.address = “321 Main St., Anytown, USA”;
e2.number = 202;
e2.SSN = 333221111;
e2.salary = 100000.00;
System.out.println(e2.name + “ “ + e2.SSN);
System.out.println(e2.computePay());
e2.mailCheck();
}
}
Search WWH ::




Custom Search