Originally Posted by
king000000
I havent done java in a while and not sure what to do with the void methods please can someone help me out thanks whole thing is in a zip file as well done in bluej as there is a long list of code here. }
you mean you've putted void method's in your code without knowing whether or not you'll use them, and even not knowing what they're supposed to do?
a void method is usually used to perform an action, without expecting a result.
for instance, two kids fighting:
in class Kid, you'd have:
public void getsKicked(String otherKidsName){
System.out.println("" + this.getName() + " got kicked by + " otherKidsName);
}
and that other kid would love this situation. but, in reality, the other kid would kick back, OO-terms thinking => he would return a result:
public String getsKicked(String otherKidsName){
System.out.println("" + getName() + " got kicked by " + otherKidsName);
return otherKidsName + " just got kicked back by " + getName + " really hard".
}
whatever you do within a void method, stays in that method (unless you go and change values of variables you didn't declare in that method.
the other version returns a String. so you could say this:
Kid a = new Kid("Burt");
Kid b = new Kid("Jeff");
b.getsKicked(a.getName());
String answer = b.getsKicked(a.getName());