Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Passing a method as a parameter problem
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hoy2Coy




PostPosted: Mon Jan 17, 2011 2:40 pm   Post subject: Passing a method as a parameter problem

I was wondering how to put a method as a parameter in Java. I know there are other posts about this but I can't make sense of them (something to do with interface, right?). I'm relatively new to Java so I just know the basics. The reason I need to be able to do this is because I'm making an interactive story with each section being its own method. In pseudo-code I want it to be something like this:

public class Interactive_Story {

void Choose(Takes methods a and b as parameters){
if (user input=="a"){
Execute method a
}else{
if (user input=="b"){
Execute method b
}
}
}

void Start(){
Output beginning of story on the console.
Choose(Do_This,Do_That)
}

void main (String[] args){
Start()
}

}

I hope you see what I'm trying to get at. If you have any ideas or informative links please post them as soon as possible.

Thanks,
Hoy2Coy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jan 17, 2011 3:06 pm   Post subject: RE:Passing a method as a parameter problem

You could have a class for a Chapter (or some other unit of a story section), and navigate through those.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: