0

I am trying to work out what may be causing this problem for a while now. I am completely new to Java and BlueJ but have been looking at this for hours and cannot figure out what is causing the problem. Keep getting the error message "Incompatible types: Plasterer cannot be converted to Apprentice". Any help is greatly appreciated.

//Purpose of Program: To create a mixed array to hold 2 different Apprentice objects - Plasterer and Carpenter //Plasterer and Carpenter //All the details of each object are then displayed to the screen.

public class MixedLists
{

  public static void main(String args[])
  {

    //Declaration of object list to hold 2 student objects
    Apprentice [] apprenticeList = new Apprentice[2];

    ////////////////////////////////////////////////////////////////////
    //Plasterer
    //Taking in values
    String NameIn, NumberIn, AddressIn, StudentIDIn, EmployerNameIn, FinalSem1GradeIn;

    System.out.println("Entering data for Plasterer");
    //Apprentice class attributes
    System.out.print("\tEnter Name:                   ");
    NameIn = EasyScanner.nextString();

    System.out.print("\tEnter telephone number:       ");
    NumberIn = EasyScanner.nextString();

    System.out.print("\tEnter Address:                ");
    AddressIn = EasyScanner.nextString();

    System.out.print("\tEnter student id:             ");
    StudentIDIn = EasyScanner.nextString();      

    //Plasterer class attributes
    System.out.print("\tEnter in Employer Name:         ");
    EmployerNameIn = EasyScanner.nextString();

    System.out.print("\tEnter Final Semester 1 Grade:    ");
    FinalSem1GradeIn = EasyScanner.nextString();

    //Initializing what is referenced by position 0 of the object list with a plasterer object
    apprenticeList[0]=new Plasterer(NameIn, NumberIn, AddressIn, StudentIDIn, EmployerNameIn, FinalSem1GradeIn);

    System.out.println("\n");

    /////////////////////////////////////////////////////////////////   
    //Carpenter
    String NameIn1,AddressIn1,Number1,StudentID1;
    //additional variables
    String awardSought,specialisation;
    double gpaModuleGrade, industrialExperienceMark;

    //Entering values for Carpenter
    System.out.println("Entering data for Carpenter");
    //Apprentice class attributes
    System.out.print("\tEnter Name:                   ");
    NameIn1 = EasyScanner.nextString();

    System.out.print("\tEnter telephone number:       ");
    Number1 = EasyScanner.nextString();

    System.out.print("\tEnter Address:                ");
    AddressIn1= EasyScanner.nextString();

    System.out.print("\tEnter student id:             ");
    StudentID1= EasyScanner.nextString();

    //Carpenter class attributes    
    System.out.print("\tEnter award sought:           ");
    awardSought = EasyScanner.nextString();
    System.out.print("\tEnter specialist area:        ");
    specialisation = EasyScanner.nextString();

    //Carpenter class attributes
    System.out.print("\tEnter GPA Module Grade:       ");
    gpaModuleGrade = EasyScanner.nextString();
    System.out.print("\tEnter industrial experience Grade: ");
    industrialExperienceMark = EasyScanner.nextString();

    //Initializing what is referenced by position 1 of the object list with a Carpenter object
    apprenticeList[1]=new Carpenter(NameIn1, AddressIn1, Number1, StudentID1,awardSought,specialisation, gpaModuleGrade,industrialExperienceMark);

    System.out.println("\n");

    ////////////////////////////////////////////////////////////////////
    //for loop to display out contents of mixed object array
    //Display out all information associated with Carpenter, Carpenter and CabinetMaker

    System.out.println("Award Details for all Apprentices in the System\n"); 
    for(int i = 0; i < apprenticeList.length; i++)
    {
        System.out.println(apprenticeList[i].printAwardDetails());
    }

  }
}

The Apprentice Class goes as such

public abstract class Apprentice
{
    //attributes

    private String Name;
    private String Number;
    private String Address;
    private String StudentID;

    public Apprentice (String NameIn, String NumberIn, String AddressIn, String StudentIDIn)
    {
        Name = NameIn;
        Number = NumberIn;
        Address = AddressIn;
        StudentID  = StudentIDIn;
    }

        //Methods to read the attributes

        public String getName()
        {
            return Name;
        }

        public String getNumber()
        {
            return Number;
        }

    public String getAddress()
    {
        return Address;
    }

    public String getStudentID ()
    {
        return StudentID ;
    }

    public void setName(String NameIn)
    {
        Name = NameIn;
    }

    public void setNumber(String NumberIn)
    {
        Number = NumberIn;
    }

    public void setAddress(String AddressIn)
    {
        Address = AddressIn;
    }

    public void setStudentID (String StudentIDIn )
    {
        StudentID  = StudentIDIn;
    }

}
Jebediah
  • 1
  • 3
  • 3
    Is `Plasterer` a subclass of `Apprentice`? – rgettman Aug 25 '15 at 21:06
  • 3
    Please add the definitions for `Plasterer` and `Apprentice` – Barranka Aug 25 '15 at 21:08
  • 1
    You're not posting the most important information (as requested above). – Hovercraft Full Of Eels Aug 25 '15 at 21:12
  • Sorry if I am not understanding properly but I have just added the apprentice class above if this is what I think you are looking for. – Jebediah Aug 25 '15 at 21:18
  • I need the classes of Plasterer and Carpenter to inherit the attributes from the Apprentice class but Iʻm not sure exactly how to do this. – Jebediah Aug 25 '15 at 21:19
  • Since you're using BlueJ I guess you also have some kind of Java book (like [Objects First with Java](http://www.bluej.org/objects-first/) (a book about learning Java with BlueJ)? If so, take it and read the chapter about _inheritance_. – Tom Aug 25 '15 at 21:28
  • I donʻt have the book but will try and find some tutorials online about inheritance. – Jebediah Aug 25 '15 at 21:36
  • I have fixed this and found out how to use superclass and subclass properly, but now I am wondering how do I link a menu with choices to these subclasses to work properly? – Jebediah Aug 25 '15 at 22:14
  • Please create a new question for this. – Tom Aug 26 '15 at 00:06

1 Answers1

0

You need to use inheritance.

Create a class named for example "Worker", then Plasterer and Apprentice should both inherit that class. You then can have a list of workers containing both Plasterers and Apprentice.

Or if "Apprentice" is just a type of Plasterer, make Apprentice inherit Plasterer (or the opposite if Plasterer is a kind of Apprentice)

realUser404
  • 2,111
  • 3
  • 20
  • 38