Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. /*
  2. * Complete the playGame(int players, int passes) method
  3. * Complete the addPlayers(int players) method
  4. * Complete the passPotatoe(int passes) method
  5. * No other methods/variables should be added/modified
  6. */
  7. public class A3CircleLL {
  8. /*
  9. * Grading:
  10. * Correctly uses helpers to play game - 1pt
  11. * Prints correct winner when game is complete - 0.5pt
  12. */
  13. public void playGame(int players, int passes) {
  14. /*
  15. * Use the helper methods addPlayers and passPotatoe to play the game
  16. * Continue passing the potato until only 1 player remains
  17. * Print the winning players number
  18. *
  19. * For players = 5 and passes = 3, the winner should be 1. Players should be removed in this order:
  20. * - 4, 3, 5, 2
  21. */
  22. }
  23. /*
  24. * Grading:
  25. * Correctly creates circular linked list of size amount - 1pt
  26. */
  27. private void addPlayers(int amount) {
  28. /*
  29. * Set up this method to create a Node for each player
  30. * The value of each Node, should be the player number, starting at 1
  31. * For example, if the amount is 5, there should be Nodes 1-5
  32. * Node 1 should always be set as the start
  33. * Make list circular by connecting the last player Node to the first
  34. */
  35. for(int i = 1; i < amount; i++) {
  36. if(i == 1) {
  37.  
  38. }
  39. }
  40. }
  41. /*
  42. * Grading:
  43. * Correctly removes the player the number of passes away from the start - 1pt
  44. * Correctly changes the start to the player after the one being removed - 0.5pt
  45. */
  46. private void passPotato(int passes) {
  47. /*
  48. * Set up this method to play a single round of the game
  49. * Move through the list the number of passes from the start
  50. * Remove the player/Node at this position
  51. * Set the start equal to the player/Node after this position
  52. * Do not play a round if there is one 1 player remaining
  53. * Print the player number that was removed and the player with the potato
  54. */
  55.  
  56. }
  57.  
  58. private Node start;
  59. private Node last;
  60. private int count;
  61. public A3CircleLL() {
  62. start = null;
  63. count = 0;
  64. last = null;
  65. }
  66. public String printList() {
  67. String output = "";
  68. if(start != null) {
  69. Node current = start;
  70. do {
  71. output += current.value + ",";
  72. current = current.next;
  73. }while(current != start);
  74. }
  75. return output;
  76. }
  77. public String toString() {
  78. return this.printList();
  79. }
  80. private class Node {
  81. Integer value;
  82. Node next;
  83. public Node(Integer v) {
  84. value = v;
  85. next = null;
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement