hi guys, i am asked to do a game where the player plays against computer where each one has to put into the pursue a piece of coin, it cas be 5cent, 10, 25 or a dollar, the one that puts the biggest piece can take the change for it from the purse minus one, example if i put a piece of 5 cent and there are already in the purse 5 ieces of one cent, i will take four of them, the one that grows empty without any piece will loose, i am asked to do this in java without usung classes, so not using the object apporach, is there any existing code for similar games that can help me ?
You'll need at least one class if you're going to make this in java, but we'll let that be.
You're going to have to figure out what the flow of this program will be, and write methods to do the work that you need done.
Take a sheet of paper and think it through at a high level. The outer level, I suppose would be something like:
decide on computer's move get player's move calculate who won and give the right change is the game over? If not, loop back. Report who won
Now, take each of those steps and think about how you'd implement them as methods. How does the computer decide on its best move? How do you get the player's move? How do you evaluate the moves once you have them?
Some of them you'll want to break down into smaller parts, and probably there will be smaller parts to those. Don't be afraid to have methods that call methods, it's better to have a lot of small methods than a ten-pager with all your logic in it.
Work out what you think each piece will have to do before you write the code for any of it, this will help you find conceptual errors before you write a bunch of code.