java 中的不兼容类型(任务)

incompatible type in java (task)

It is my first lang, so i am new in that field. Please, help me. I am doing my assignment and I received the mistake in process of compilation:"incompatible types". The first class I have done before and it is works. Employee class I should`t touch anymore.

class Employee{

   private String firstName; // First name of employee
   private String lastName; // Last name of employee
   private String id; // Personal id number of employee
   private String emNum; // Employee number

   static int counter = 0; // The counter variable will keep track the number of employee

   public Employee(String firstName, String lastName, String id)
   {
      this.firstName = firstName; 
      this.lastName = lastName; 
      this.id = id; 
      emNum = "EMPTY";
      counter++;
   }

   public void setFirstName(String firstName)
   {
      this.firstName = firstName;
   }

   public String getFirstName()
   {
      return firstName;
   }

   public void setLastName(String lastName)
   {
      this.lastName = lastName;
   }

   public String getLastName()
   {
      return lastName;
   }

   public void setid(String id)
   {
      this.id = id;
   }

    public String getid()
   {
      return id;
   }

   public void setEmNum(String emNum)
   {
      this.emNum = emNum;
   }

   public String getEmNum()
   {
      return emNum;
   }

   public static int getNumberOfEmployees()
   {
      return counter;
   }

   public String toString()
   {
      if(emNum == "EMPTY"){
        setEmNum("Employee number:No employee number has been assigned yet!");
      }
      else
         return emNum;

      return ("\n\tFirst Name: " + getFirstName() + " " +"Last Name: " + getLastName() 
                 + " " +  "\n\tId number: " + getid() + " " + "\n\tEmployee number: " + getEmNum() );
   }

}

In the A1Q2 class i have problem. In the loop i wanted to create the list of those employees in ONE array. It shows "cannot find symbol" mistake. Actually, I see that types r different, so it cannot write String type into Employee, but i don`t understand how to fix it.

required: Employee
found: java.lang.String

class TestA1Q2
{
  public static void main(String[] args)
  {
    String[] firstNames= {"Fred","John","Amir", "James","Bob","Jay","Amber"};
    String[] lastNames = {"Bond","Kates","Memar", "White","Marley","Brown","Nogofski"};
    String[] idNumbers = {"R111111","A222222","AB11111", "KR22121","V311133","L242434","P102432"};
    String[] employeeNum = {"1111","2222","3333", "4444","5555","6666","7777"};

    Employee[] list = new Employee[firstNames.length];
    list = listOfEmployees(firstNames,lastNames,idNumbers); // create the list of employees in one array 
    System.out.println(list);
    System.out.println(Employee.getNumberOfEmployees());
  }
  // DON`T TOUCH ABOVE PART


  static Employee[] listOfEmployees(String[] firstNames, String[] lastNames, String[] idNumbers)
  { 
     Employee[] employee = new Employee[firstNames.length];
     for (int i = 0; i < firstNames.length; i++){
        employee[i] = firstNames[i] + lastNames[i] + idNumbers[i];
     }
     return employee;
 }
}

您正在联系字符串并试图将它们存储到 Employee 数组中。您必须使用 firstName、lastName 和 ID 创建一个新的员工对象,然后将引用存储在 Employee 数组中。

Employee[] employee = new Employee[firstNames.length];
     for (int i = 0; i < firstNames.length; i++){
        employee[i] = new Employee(firstNames[i],lastNames[i],idNumbers[i]);
     }
     return employee;

Post 如果有效,请返回。

我不相信一个列表可以是 3 维的(包含名字、姓氏、idNumbers)。如果您创建了 3 个列表,listFirstNames、listLastNames、listIDNumbers,同时填充它们可能有效:

Employee[] employee = new Employee[firstNames.length];
     for (int i = 0; i < firstNames.length; i++){
         listFirstNames[i] = firstNames[i];
         listLastNames[i] = lastnames[i];
         listIDNumbers[i] = idNumbers[i];
     }
}