create and array with variable names
I'm trying to see how i can create and array with employee names
All i see is examples with already pre poplulated employee names , I want to enter my own via JOptionPane.
public class EmployeeInfo
{
private String EmpName; // Name of Employee
private int HoursWorked; // number of regular hours worked
private int HoursOT; // number of hours over 40 worked
private int Pay; // regular pay 20.00 per hour 40 hrs or less
private int PayOT; // overtime pay of hours over 40 at 1.5 times regular pay
Sting[] Name; // array to store names
int [] HoursWorked; // array to store hours worked
Name[] EmpName = new Name[3]
EmpName[0] = new Name ();
EmpName[1] = new Name ();
EmpName[2] = new Name ();
}
This is what i have but so fare but what is it that will allow me to set the array to take any employee names
thank you
Re: create and array with variable names
Code:
EmpName[0] = new Name ();
That is incorrect syntax. It makes Name look like the name of a class because of the new
The same here:
Code:
Name[] EmpName = new Name[3]
Name is used here like it is the name of a class.
Replace the "new Name()" with the String that you want to assign to that slot in the EmpName array.
You need to look at your lessons where it describes how to code a variable definition.
I'm assuming that Name is not a class.