Selecting which dice to re-roll

I am trying to teach myself how to program in Java, and I am writing a Yahtzee program, which I thought would be considerably simpler than it actually is. I am having difficulty figuring out how to select a certain number of dice to re-roll, for example say the first roll produces: 2, 4, 2, 1, 2, and the player wants to re-roll the 4 and 1. The way I am doing it now is by asking how many dice the player wants to re-roll, and then having different methods for each answer 0 to 5, so with the example roll above the player would input 2, then would be prompted to input the places of the two dice he wants to re-roll, so he would input 2 and 4, which would then cause these two dice to be re-rolled, but I know there has to be a much easier way to do this. If someone could point me in the right direction, it would be greatly appreciated. As you can see I haven't wrote the code for the methods yet, because I realized there has to be an easier way.

Re: Selecting which dice to re-roll

The best way to do this would be to have a Die class to represent the 5 dice. In that class you would have an instance variable of type boolean to keep track if it should be rolled or not. Then iterate over your 5 Die objects and if the boolean is set to true* roll it again.

Re: Selecting which dice to re-roll

Thank you very much for your feedback. I actually decided to do it a different way. I think it might make it a little easier if later I decide to attempt to convert it to a GUI program. If you could please take a look at it and give me any critiques it would be appreciated. Specifically if you could give me advice for methods I am really struggling with this, looking at my code am I doing it correctly (most efficiently). Thank You.

Re: Selecting which dice to re-roll

Don't worry about efficiency. If you program performs like crap, then is a good time. For learning to code, "most efficient" is the least of your concearns.

I think it might make it a little easier if later I decide to attempt to convert it to a GUI program.

That's where you're wrong. It will be harder. Imagine you having all this spaghetti code, and then have to write a GUI program around it. It surely doesn't help. Being able to move responsibilities to the right classes is very important. Even for little command line games.

I have to agree with Junky about the Die class. It makes your coding life much easier: