Results 1 to 2 of 2
  1. #1
    jmrire is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default Re: create and array with variable names

    Java 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:
    Java 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.

Similar Threads

  1. stepping through numbered variable names
    By PuppetJacks in forum New To Java
    Replies: 3
    Last Post: 11-04-2011, 09:37 AM
  2. Dynamic variable names
    By reuben2011 in forum New To Java
    Replies: 8
    Last Post: 08-31-2011, 05:42 PM
  3. Replies: 0
    Last Post: 04-12-2009, 04:06 AM
  4. [SOLVED] Can variable names be dynamically created?
    By CJSLMAN in forum New To Java
    Replies: 4
    Last Post: 01-03-2009, 02:06 AM
  5. building file and variable names from variables
    By madad2005 in forum New To Java
    Replies: 2
    Last Post: 07-18-2007, 05:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •