0

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

5
  • 1
    No one can help you unless you provide code (the constructor definition). Also, please add a language tag. Commented May 28, 2013 at 13:21
  • We need to see the definitions of Person and Trainee. Already, it looks a little odd because new Trainee would 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. Commented May 28, 2013 at 13:27
  • Do you have any constructor for Trainee that takes 7 Strings? Commented May 28, 2013 at 13:27
  • yes, but its 5 strings and 2 int Commented May 28, 2013 at 13:33
  • There's still a bug in your Trainee constructor: super(myFirstName,myLastName,myStreetAddress,myPhoneNumb,myPostCode); You'll need to swap the last two parameters. Commented Apr 23, 2018 at 16:47

1 Answer 1

2

Check the type of the phoneNumb parameter.

Sign up to request clarification or add additional context in comments.

5 Comments

It's int like it needs to be everywhere, cant be that.
But what type is the phoneNumb variable that you are passing for that parameter?
I dont get what you are asking, sorry, why do you thin its the phoneNumb anyways?
@Yazz: Because you define phoneNumbas String, but the Trainee constructor expects it to be an int.
I think I see what you are talking about, let me try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.