Page 1 of 1

Write a program that find the winner of the following game called Hot Potato. Hot potato rules: 1. The person who starts

Posted: Fri Jul 08, 2022 6:44 am
by answerhappygod
Write A Program That Find The Winner Of The Following Game Called Hot Potato Hot Potato Rules 1 The Person Who Starts 1
Write A Program That Find The Winner Of The Following Game Called Hot Potato Hot Potato Rules 1 The Person Who Starts 1 (167.26 KiB) Viewed 60 times
Write a program that find the winner of the following game called Hot Potato. Hot potato rules: 1. The person who starts with the potato passes it to the next person in the circle. 2. After n (given number) of passes, the potato "explodes". 3. Whoever is holding the potato and the person when it explodes and the person (called it x) is out and leaves the circle. Also, the person who passed the potato to person a right before it explodes will leave the circle as well. 4. The person after them starts with the potato in the next round, and repeats the same procedure starting at step 1. 5. When there's only one person left in the circle they're the winner. Program Input The program gets the following input values stored in a txt file called input.txt (see an example here): ● names of players in a list separated by comma • and the number n which shows the number of passes before the potato explodes (see step 2). Program Output The program determines whether the game has a winner or not. If the game has a winner (the person who remains in the circle after everyone else leaves), the program will print out the winner's name on the screen. For example, given the list of players and the number n 12 in the input file example, here is the winner (the person with asterisk has the potato in step 1): pass 1: Ann*, Ross, John, Alice, Bob, Bill, Joe, Alex, Mary, Teddy, Rose Ann and Ross are out! pass 2: John*, Alice, Bob, Bill, Joe, Alex, Mary, Teddy, Rose Bob and Bill are out! pass 3: John, Alice, Joe*, Alex, Mary, Teddy, Rose Rose and John are out! pass 4: Alice*, Joe, Alex, Mary, Teddy Joe and Alex are out! pass 5: Alice, Mary*, Teddy Alice and Mary are out! Pass 6: Teddy is the winner! In the case that the number of players is even, there will be no winner, b/c in each pass, two players are out and at the last pass no player remain in the circle. Solution Idea using Circular Linked List Use the SinglyLinked List<> class implemented earlier in the course to construct a circular linked list of names (Strings) of the players in the game. Eliminate nodes of players who will be out in each pass. When you reach to only one node in the list, announce the winner! Submission Submit a zip file compressing all of the java files for your program.