• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help fixing up my program?  RSS feed

 
John Sing
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have to create a program that plays an elimination game. The user has to input the number of players and the number of "cycles" or how much the program counts by. So for example if I input 8 players and 4 cycles then the first player out will be player 4 and then the next one would be player 8, and then it goes on and on until there is one winner. I thought I finished my program but for some reason it gets the wrong answer half the time. Then to make matters worse my teacher decided to tell us that we can't use array lists and we have to use arrays instead today... So I really need some help changing my code to have an array in it and making it work. Here is my code



 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you got so much code in the main method?
Why are you using option panes for keyboard input rather than a Scanner?
I presume you will have a List whose size is the same as one of the numbers you enter? Why can't you create an array that size?
Please explain how you are eliminating the players. If you are removing things from a LIst, that is much easier than removing things from an array. You would have to move all the following elements one place up and maybe null out the last element. Are you aware of the System#arraycopy() method? There are also copying methods in the Arrays class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!