Reputation: 9
I am doing an assignment but I am stuck on this step. How would I Call the findInstructor method passing the instrFirst and instrLast parameters to find the Instructor teaching the course"? how do I call a method that is private. any suggestion would be helpful thx
private Instructor findInstructor(String instrFirst, String instrLast){
}
public void addCourse(String crseNumber, int credits, String instrFirst,
String instrLast)
{
" Call the findInstructor method passing the instrFirst and
instrLast parameters to find the Instructor teaching the
course"
}
Upvotes: 0
Views: 1306
Reputation: 3609
Private access means that you can call this method only if you are inside of the same class as that method. You are unable to access that method from outside of the class containing it.
These two parameters you are asked to pass have to be included in the list of parameters of the method addCourse()
. Inside of its body you then use references names included in the list of parameters of addCourse()
to pass them as arguments to the findInstructor()
method (in your example it is instrFirst
and 'instrLast' - the same as in findInstructor()
list of arguments but it could be anything, it doesn't have to match references names exactly, because these names are used only locally, just the type of arguments must be the same).
The proper way to call that method inside of other method is the following:
public void addCourse(String crseNumber, int credits, String instrFirst, String instrLast) {
/* the next line means that you assign the result of calling the findInstructor() method to variable instr */
Instructor instr = findInstructor(instrFirst, instrLast)
}
Upvotes: 0
Reputation: 103351
Here you have, it's very simple
private Instructor findInstructor(String instrFirst, String instrLast){
}
public void addCourse(String crseNumber, int credits, String instrFirst,
String instrLast)
{
Instructor instructor = findInstructor(instrFirst,instrLast);
}
findInstructor method must be in the same class as the addCourse method.
Upvotes: 1