the code is:
Person aTrainee = new Trainee (firstName,lastName,streetAddress,postCode,phoneNumb,performanceAverage,trainingArea);
and the error says
no suitable constructor found for Trainee...ectect
Person is an array
Trainee is an item in the array (one of three, trainee, employee and management)
If I remove the items in the brackets then I do not get the error, but without it, the code does not work. I have made sure that the items in the brackets match up with the rest of the code 10+ times, I have spent over 1 hour trying to figure this out, I would love ANY advice you can give me.
edit: this is the code, there is A LOT of it so here is the important part.
else if (userChoice.equalsIgnoreCase(toTrainee))
{
Scanner in = new Scanner(System.in);
Scanner choice = new Scanner (System.in);
System.out.println("To select a Trainee to edit, enter a value from 0 to 3: \n");
int selection = choice.nextInt();
if(selection <= 8)
{
System.out.println("Incorrect, please enter a valid number!");
sc.nextLine();
break;
}
System.out.println("Please enter a first name for the Trainee \n");
String firstName = in.nextLine();
System.out.println("Please enter a Last name for the Trainee \n");
String lastName = in.nextLine();
System.out.println("Please enter a Street Address for the Trainee: \n");
String streetAddress = in.nextLine();
System.out.println("Please enter a Post code for the Trainee: \n");
int postCode = in.nextInt();
in.nextLine();
System.out.println("Please enter a Phone Number for the Trianee: \n");
String phoneNumb = in.nextLine();
System.out.println("Please enter a performance average for the Trainee: \n");
String performanceAverage = in.nextLine();
System.out.println("Please enter a Training area for the Trainee: \n");
String trainingArea = in.nextLine();
Person aTrainee = new Trainee (firstName,lastName,streetAddress,postCode,phoneNumb,performanceAverage,trainingArea);
System.out.println(aTrainee);
myWorker.set(selection,aTrainee);
}
Trainee constructor
public class Trainee extends Person
{
private String performanceAverage, trainingArea;
public Trainee()
{
super();
performanceAverage = "";
trainingArea = "";
}
public Trainee(String myFirstName, String myLastName, String myStreetAddress, int myPostCode, int myPhoneNumb, String myPerformanceAverage, String myTrainingArea)
{
super(myFirstName,myLastName,myStreetAddress,myPhoneNumb,myPostCode);
performanceAverage = myPerformanceAverage;
trainingArea = myTrainingArea;
}
public void setPerformanceAverage(String myPerformanceAverage)
{
this.performanceAverage = myPerformanceAverage;
}
public void setTrainingArea(String myTrainingArea)
{
this.trainingArea = myTrainingArea;
}
public String toString()
{
return super.toString() + ", Performance Average is " + performanceAverage + ", and Training Analysis is " + trainingArea;
}
}
This is Person which gives Trainee a few more things like Name ect.
public class Person
{
private String firstName;
private String lastName;
private String streetAddress;
private int postCode;
private int phoneNumb;
public Person()
{
firstName = lastName = streetAddress = "";
postCode = phoneNumb = 0;
}
public Person(String myFirstName, String myLastName, String myStreetAddress, int myPostCode, int myPhoneNumb)
{
firstName = myFirstName;
lastName = myLastName;
streetAddress = myStreetAddress;
postCode = myPostCode;
phoneNumb = myPhoneNumb;
}
public void setFirstName(String myFirstName)
{
this.firstName = myFirstName;
}
public String getFirstName()
{
return firstName;
}
public void setLastName(String myLastName)
{
this.lastName = myLastName;
}
public String getLastName()
{
return lastName;
}
public void setStreetAdress(String myStreetAddress)
{
this.streetAddress = myStreetAddress;
}
public String getStreetAdress()
{
return streetAddress;
}
public void setPostCode(int myPostCode)
{
this.postCode = myPostCode;
}
public int getPostCode()
{
return postCode;
}
public void setPhoneNumb(int myPhoneNumb)
{
this.phoneNumb = myPhoneNumb;
}
public int getPhoneNumb()
{
return phoneNumb;
}
public String toString()
{
return "This person's information is: " + firstName + " " + lastName + ", " + " " + streetAddress + " " + postCode + ", phone number is " + phoneNumb;
}
}
and this is the array (note the first line is just a test so ignore the entries)
import java.util.ArrayList;
public class ShopMan
{
public static void main()
{
ArrayList<Person>myWorker = new ArrayList<Person>();
Person aShopEmployee = new ShopEmployee("Yazz","Hasan","1/43", 4215, 55271095, "Timber", 010101001, 50000);
myWorker.add(aShopEmployee);
aShopEmployee = new ShopEmployee("","","",00,00,"",00,00);
myWorker.add(aShopEmployee);
aShopEmployee = new ShopEmployee("","","",00,00,"",00,00);
myWorker.add(aShopEmployee);
aShopEmployee = new ShopEmployee("","","",00,00,"",00,00);
Person aManagement = new Management("","","",00,00,"",00,00,false);
myWorker.add(aManagement);
aManagement = new Management("","","",00,00,"",00,00,false);
myWorker.add(aManagement);
aManagement = new Management("","","",00,00,"",00,00,false);
myWorker.add(aManagement);
Person aTrainee = new Trainee("", "", "", 00, 00, "", "");
myWorker.add(aTrainee);
aTrainee = new Trainee("", "", "", 00, 00, "", "");
myWorker.add(aTrainee);
aTrainee = new Trainee("", "", "", 00, 00, "", "");
myWorker.add(aTrainee);
aTrainee = new Trainee("", "", "", 00, 00, "", "");
myWorker.add(aTrainee);
aTrainee = new Trainee("", "", "", 00, 00, "", "");
myWorker.add(aTrainee);
aTrainee = new Trainee("", "", "", 00, 00, "", "");
myWorker.add(aTrainee);
aTrainee = new Trainee("", "", "", 00, 00, "", "");
myWorker.add(aTrainee);
for (int i=0; i < myWorker.size(); i++)
{
System.out.println(myWorker.get(i));
}
while (true)
{
Menu.main(myWorker);
}
}
}
ANSWER FOUND!
String phoneNumb = in.nextLine();
needed to be
int phoneNumb = in.nextInt();
in.nextLine();
Thank you so much to Russell Zahniser and creinig and everyone else
new Traineewould generate a trainee object, but you're assigning it to an object which represents an array of objects, at least based upon how you describe them.Traineeconstructor:super(myFirstName,myLastName,myStreetAddress,myPhoneNumb,myPostCode);You'll need to swap the last two parameters.