Hello, having a hard time using my Faculty class, where I have to initialize/createObject from my Education class to Faculty. I would like to use the constructors from the Education class, to be implemented to my Faculty class. Here is my attempt Here's my two codes.

public class Education {
    String degree;
 String major;
     String research;

    public Education()
    {
        degree = "";
        major = "";
        research = "";
    }
    public Education(String degree, String major, String research){   
        this.degree = degree;
        this.major = major;
        this.research = research;

    }
      public void setDegree(String degree)
      {
        this.degree = degree;
      }
      public String getDegree()
      {
        return degree;
      }
      public void setMajor(String major)
      {
        this.major = major;
      }
      public String getMajor()
      {
        return major;
      }
      public void setResearch(String research)
      {
        this.research = research;
      }
      public String getResearch()
      {
        return research;
      }
}

This education is fine.

mport java.util.Calendar;

public class Faculty <T> extends Employee implements EmployeeInfo {


        private String level;

    Education degree = new Education();
    Education major = new Education();
    Education research = new Education();
    /**
     * Default constructor
     */
    public Faculty() {
        super();

    }

    public Faculty(String name, int idNumber, char gender, Calendar birthdate,
            String level, Education degree, Education major, Education research ) {
        super(name, idNumber, gender, birthdate);
        this.level = level;
        this.degree = degree;
        this.major = major;
        this.research = research;

    }
    public String getLevel() {
        return level;
    }
    public void setLevel(String level) {
        this.level = level;
}
    public double monthlyEarning() {
        // TODO Auto-generated method stub
        return 0;
    }

       public boolean equals(Object o) {
              if(o instanceof Faculty)
                return getIdNumber() == ((Faculty) o).getIdNumber(); 
              else
                return false; 
            }
        public String toString() {
            return "\n\nID Employee Number: " + getIdNumber() + 
                "\nEmployee Name: " + getEmployeeName() + 
                "\nSex: " + getGender() +
                "\nBirth date: " + getBirthdate().get(Calendar.YEAR) + "/" + getBirthdate().get(Calendar.MONTH) + "/" + getBirthdate().get(Calendar.DATE) +
                "\nLevel: " + getLevel() + 
                "\nDegree:" + getDegree() + //This is what I want to work

                "\nMonthly Salary: " + monthlyEarning();
        }

This is my attempt. Line 51 is where I want to use "get.Degree". It can't access it from the Education class. The eclipse program wants me to create the method, which already did in my Education class. So any pointers is appreciate on how I can do this. I'll still play around the code though.

Recommended Answers

All 4 Replies

Lines 8,9,10 are redundant - a single Education object contains values for degree, major and research, so all you need is a single instance of Education - let's call that variable "education" for the moment, and assume you initialise it with a complete instance of each Faculty's Education.
Now on line 51 you want to get the degree info from that Education.
No problem, the Education class has a suitable method, so you can just use that...
education.getDegree()

Alright I did what you said, and it works. Preesh. I'll mark this as solved
I understand about objects as well while playing around.

Change line 8,9,10 with
Education education;
then inside your non parameterized constructor at line 16 write
education=new Education();
inside your parameterized constructor change line 23,24,25 with
education=new Education("some degree","some major","some research");
and then at line 51 you can access degree by
education.getDegree();

Hi sandipan quosh, welcome to DaniWeb

Here at DaniWeb we try to help people learn Java and develop their Java skills.
Please don't just spoon-feed them a solution without any explanation of why/how it works.
ps: You also just repeated exactly the same solution from a previous post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.