If I haven't got you wrong, I can say it is an easy task to accomplish. Of course, I can't write the whole class for you here, but I certainly can give you a hint.
Again if I haven't got you wrong, you got a problem with method overloading, which is not a problem at all. The idea behind overloading is that the programmer should have the freedom to group methods that have a similar, or sometimes the same function.
A method is distinguished from others by these attributes:
1) its name
2) its parameters
(I agree this is not clear enough, but this is not the place to be more verbose.)
Thus, you could create your overloaded method like this:
public void setCustomerInfo(Customer c, String newName, String newPhone){
c.name=new String(newName);
c.phone=new String(newPhone);
}
public void setCustomerInfo(Customer c, String newName, String newPhone, String newEmail){
c.name=new String(newName);
c.phone=new String(newPhone);
c.email=new String(newEmail);
}
I assume you have already defined relevant instance variables in your definition of class Customer. I believe this will compile perfectly well. Note that, although the names are the same, the signatures are different, which practically make these two separate methods.
I'm trying to make some amateur progress in Java myself, please forgive me my mistakes if there are any.
|