Something I must have missed in Java...?
So this will probably be a simple answer for most of you, but I guess I somehow never learned this in my first java class, and now it's important.
Lets say I am writing a program for a game. This game has a few different classes in it, and they need to be available to eachother.
We'll say I have a main method in the first class, which prompts the user for inputs, such as the size of the game board.
Now I have another method that creates the game board.
I have a third method that displays the game board.
a fourth method that places pieces etc.
So, what I need to do, is run the main method, take the inputs and run them in the "createboard", then use what I have to run "display board" and finally run the "addpiece" methods, followed by "displayboard" again. After this, addpiece and display board and whatever else is involved will need to be used again and again until the game is over.
Long question shorter....how do I call the other methods, get them to run, and then return to the main method so that I can call the next one?
It seems simple, I must be missing something.
- Anonymous9 years agoFavorite Answer
give the method a name and then type is code. relate the code to that name and then when you need to call them just type the code to call the name you gave to the method and it should run.
It has been 3 years since I did Java so I cant really remember the details but that's how you do it in general