Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default an array probelm

    hi, I'm learning to code java on my own because I want to learn something new. anyways, I'm having a problem with an array. I made a seperate class called employee.

    here is what is in the employee class which is separate from the main class

    String employee number;
    String First;
    String Last;
    int age;
    String jobtitle;
    int pay;
    employee(){
    employeenumber = "";
    First = "";
    Last = "";
    age = 0;
    jobtitle = "";
    pay = 0;
    }

    I then made a new array called

    public static employee [] emp = new employee[8];

    with the three there because there are only eight employee's. here's where my problem begins. when I input the employee's data like this

    emp[0] = new employee("123456789","david","banner", 34,"busser",45);

    the bold is underlined red with the error stating that "the constructor employee(string,string,string, int, string,int) is undefined. what did I do wrong here?

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    929
    Rep Power
    2

    Default Re: an array probelm

    Read the error precisely: "The constructor with these parameters is not defined". Your code indeed does not contain a constructor that looks like that. Solution: create one: public Employee( String id, String firstName, String lastName, int age, String jobTitle, int pay)

    Java has guidelines for naming and case of your code. Read the Java naming guidelines: Code Conventions for the Java Programming Language: 9. Naming Conventions
    Last edited by SurfMan; 11-18-2013 at 09:05 AM. Reason: Named parameters properly
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    dd09wrx is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: an array probelm

    You need to ensure that the employee class has a constructor with the following arguments int,string,string,int,string,int

    you could paste this method into your employee class

    public employee(int employeeNumber,String firstName,String lastName,int pay,String jobtitle,int age){
    this.employeenumber = employeeNumber;
    this.First = firstName;
    this.Last = lastName;
    this.pay=pay;
    this.jobtitle=jobtitle;
    this.age=age;
    }

  4. #4
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: an array probelm

    that works, thank you guys!

  5. #5
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: an array probelm

    forgive the double post but say that I want the user to select one of three choices(Y,N, or P) and if they input anything else the validation will flag it as false. how would I go about doing this? I tried if(!input==Y)||!(input==N)||!(input==P)) but that doesn't work. I also tried replacing the or function with && but that doesn't work either. could I get a hint at what I should do in this case?

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: an array probelm

    Java Code:
    if(!input==Y)||!(input==N)||!(input==P))
    Remember in an OR logic statement only one condition needs to be true. If user enters a "N" or "P" then the first condition is true. If the user enters a "Y" then the second condition will be true. Therefore the if statement will always be true regardless of what user enters.

  7. #7
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: an array probelm

    ah, I gotcha. one last question, is it possible to validate a person's full name without separating it to first=input and last = input?

Similar Threads

  1. Database probelm:No Data found
    By danpotter in forum New To Java
    Replies: 2
    Last Post: 04-06-2012, 07:17 PM
  2. Gridbag Layout Probelm
    By hemanthjava in forum AWT / Swing
    Replies: 3
    Last Post: 12-04-2007, 05:12 PM
  3. Dom4j probelm with clearContent method
    By aorteu in forum New To Java
    Replies: 0
    Last Post: 11-23-2007, 03:36 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
  •