C
conmulligan
Hi all,
I'm new to Java so bear with me.
I want to store a bunch of object references in an array.
Here's what I have:
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
// payroll class
// ------------
public class Payroll {
public static void main(String args[]) {
Employee employee[];
String output = "";
// instatiate employee classes
Boss boss = new Boss("John", "Smith", 800.0);
CommissionWorker commissionWorker = new CommissionWorker("Sue",
"Jones", 400.0, 3.0, 150);
PieceWorker pieceWorker = new PieceWorker("Bob", "Lewis", 2.5, 200);
HourlyWorker hourlyWorker = new HourlyWorker("Karen", "Price",
13.75, 40);
DecimalFormat precision2 = new DecimalFormat("0.00");
// add boss earnings to output
employee[0] = boss;
output += employee[0].toString() + " earned $" +
precision2.format(employee[0].earnings()) + "\n" +
boss.toString() + " earned $" + precision2.format(boss.earnings()) +
"\n";
// add commission worker earnings to output
employee[1] = commissionWorker;
output += employee[1].toString() + " earned $" +
precision2.format(employee[1].earnings()) + "\n" +
commissionWorker.toString() + " earned $" +
precision2.format(commissionWorker.earnings()) + "\n";
// add piece worker earnings to output
employee[2] = pieceWorker;
output += employee[2].toString() + " earned $" +
precision2.format(employee[2].earnings()) + "\n" +
pieceWorker.toString() + " earned $" +
precision2.format(pieceWorker.earnings()) + "\n";
// add hourly worker earnings to output
employee[3] = hourlyWorker;
output += employee[3].toString() + " earned $" +
precision2.format(employee[3].earnings()) + "\n" +
hourlyWorker.toString() + " earned $" +
precision2.format(hourlyWorker.earnings()) + "\n";
// display the contents of output
JOptionPane.showMessageDialog(null, output, "Payroll",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
With this code I get the following error:
variable employee might not have been initialized
employee[0] = boss
The Employee class is abstract so I cannot instatiate it.
Any ideas?
I'm new to Java so bear with me.
I want to store a bunch of object references in an array.
Here's what I have:
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
// payroll class
// ------------
public class Payroll {
public static void main(String args[]) {
Employee employee[];
String output = "";
// instatiate employee classes
Boss boss = new Boss("John", "Smith", 800.0);
CommissionWorker commissionWorker = new CommissionWorker("Sue",
"Jones", 400.0, 3.0, 150);
PieceWorker pieceWorker = new PieceWorker("Bob", "Lewis", 2.5, 200);
HourlyWorker hourlyWorker = new HourlyWorker("Karen", "Price",
13.75, 40);
DecimalFormat precision2 = new DecimalFormat("0.00");
// add boss earnings to output
employee[0] = boss;
output += employee[0].toString() + " earned $" +
precision2.format(employee[0].earnings()) + "\n" +
boss.toString() + " earned $" + precision2.format(boss.earnings()) +
"\n";
// add commission worker earnings to output
employee[1] = commissionWorker;
output += employee[1].toString() + " earned $" +
precision2.format(employee[1].earnings()) + "\n" +
commissionWorker.toString() + " earned $" +
precision2.format(commissionWorker.earnings()) + "\n";
// add piece worker earnings to output
employee[2] = pieceWorker;
output += employee[2].toString() + " earned $" +
precision2.format(employee[2].earnings()) + "\n" +
pieceWorker.toString() + " earned $" +
precision2.format(pieceWorker.earnings()) + "\n";
// add hourly worker earnings to output
employee[3] = hourlyWorker;
output += employee[3].toString() + " earned $" +
precision2.format(employee[3].earnings()) + "\n" +
hourlyWorker.toString() + " earned $" +
precision2.format(hourlyWorker.earnings()) + "\n";
// display the contents of output
JOptionPane.showMessageDialog(null, output, "Payroll",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
With this code I get the following error:
variable employee might not have been initialized
employee[0] = boss
The Employee class is abstract so I cannot instatiate it.
Any ideas?