C'est mon premier lang, donc je suis nouveau dans ce domaine. Aidez-moi, s'il vous plaît. Je fais ma mission et j'ai reçu l'erreur en cours de compilation: "types incompatibles". Le premier cours que j'ai fait auparavant et ça marche. Je ne devrais plus toucher à la classe des employés.type incompatible en Java (tâche)
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());
}
}
Dans la classe i ont A1Q2 problème. Dans la boucle, je voulais créer la liste de ces employés dans un tableau. Il montre "ne peut pas trouver le symbole" erreur. En fait, je vois que les types r sont différents, donc il ne peut pas écrire le type String dans Employee, mais je ne comprends pas comment le réparer.
requis: Employé
trouvé: 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;
}
}
Tout d'abord, vous devez fournir le contexte (ou numéro de ligne pour l'erreur). Deuxièmement, vous n'avez pas articulé vos intentions ou votre objectif pour l'employé [i] = firstNames [i] + lastNames [i] + idNumbers [i]; –