View Single Post
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Java program cd player need some help please

 
0
  #2
Oct 24th, 2008
Originally Posted by king000000 View Post
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:
  1. public void getsKicked(String otherKidsName){
  2. System.out.println("" + this.getName() + " got kicked by + " otherKidsName);
  3. }
  4.  
  5. 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:
  6.  
  7. public String getsKicked(String otherKidsName){
  8. System.out.println("" + getName() + " got kicked by " + otherKidsName);
  9. return otherKidsName + " just got kicked back by " + getName + " really hard".
  10. }

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:

  1. Kid a = new Kid("Burt");
  2. Kid b = new Kid("Jeff");
  3.  
  4. b.getsKicked(a.getName());
  5. String answer = b.getsKicked(a.getName());
Reply With Quote