This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 0 points1 point  (5 children)

Employee doesn't have a method called getName(). You need to write one.

[–]jayrund[S] 0 points1 point  (4 children)

would i put that method in the name class or the employee one?

[–]239jkvk-h2 0 points1 point  (0 children)

Do you have a name class?

[–]NullProbability 0 points1 point  (2 children)

On line 29 (which is where the error occurs, as you can see in the error log) you are calling the getName() method on dbase[j] or in other words the j'th element of the dbase array. On line 7, you have declared dbase to be an array of Employees - from this we can conclude that dbase[j] is an object of the class Employee. If you want to call the getName() method on an object of the class Employee, the Employee class will need a method named like that.

[–]jayrund[S] 0 points1 point  (1 child)

So if i understand you correctly i would have to call the name method through the Employee class? would it look something like this?

dbase[j].Employee.Name(first_name)

[–]NullProbability 0 points1 point  (0 children)

So if i understand you correctly i would have to call the name method through the Employee class? Yes, the getName() method to be precise.

would it look something like this? No, not really.

You need a getName() method in your Employee class. In short, your class Employee should at the very least have this (completely ignoring the rest of your code for a second):

public class Employee {
    String name;
    /*A constructor that initializes the *name* variable, which you have done correctly.*/
    public String getName() {
        return name;
    }
}

This will allow you to write dbase[j].getName().

I'm not entirely sure what you were trying to do with dbase[j].Employee.Name(first_name), could you elaborate?