I'm having issues with calling a method defined in a subclass on a superclass object. This program is an exercise using inheritance, with an Employee superclass, Salaried and Hourly classes that extend the superclass and a Temp class that extends the Hourly class. From what I've read, this shouldn't be happening, since the object in employees[0] is a Salaried object.
The input is a text file with every line being some piece of information, in the following format:
typeOfEmployee - Salaried, Hourly, etc.
SSN
lastName, firstName
addressLine1
addressLine2
filingStatus-exemptions
...employee specific lines...such as hours, totalPay, benefitAdjustme nt, etc.
nextEmployee
etc.
etc.
nextEmployee
etc.
etc.
I'm using Windows XP SP2 and have the most current JDK.
I know that the first entry in the Employee array is a Salaried object because I wrote a test input, and in the Salaried subclass of Employee there is a public method getTotalPay() that should return the total pay.
I keep getting a "cannot find symbol" error with the symbol being the getTotalPay() method and it says the location is in the Employee class. Any suggestions for a beginning programmer? Look at line 66.
The input is a text file with every line being some piece of information, in the following format:
typeOfEmployee - Salaried, Hourly, etc.
SSN
lastName, firstName
addressLine1
addressLine2
filingStatus-exemptions
...employee specific lines...such as hours, totalPay, benefitAdjustme nt, etc.
nextEmployee
etc.
etc.
nextEmployee
etc.
etc.
I'm using Windows XP SP2 and have the most current JDK.
Code:
import java.util.*;
import java.util.regex.*;
public final class Driver {
public static Employee[] employees = new Employee[1024];
public static int employeeCount;
public static void main( String[] args ) {
Scanner s = new Scanner(System.in);
s.useDelimiter("\r\n");
while (s.hasNext()) {
String line = s.next();
if (line.equals("")) {
continue;
} else if (line.equals("SALARIED")) {
String[] lines = new String[8];
for (int k = 0; k < 8; k++) {
lines[k] = s.next();
}
employees[employeeCount++] = new Salaried(lines);
} else if (line.equals("HOURLY")) {
String[] lines = new String[8];
for (int k = 0; k < 8; k++) {
lines[k] = s.next();
}
employees[employeeCount++] = new Hourly(lines);
} else if (line.equals("TEMP")) {
String[] lines = new String[8];
for (int k = 0; k < 8; k++) {
lines[k] = s.next();
}
employees[employeeCount++] = new Temp(lines);
}
} System.out.println(employees[0].getTotalPay());
}
}
I keep getting a "cannot find symbol" error with the symbol being the getTotalPay() method and it says the location is in the Employee class. Any suggestions for a beginning programmer? Look at line 66.
Comment