Write a program in java that finds the winner of the following game called Hot Potato. Hot potato rules: Program Input T
Posted: Sun Jul 03, 2022 11:22 am
Write a program in java that finds the winner of the followinggame called Hot Potato.
Hot potato rules:
Program Input
The program gets the following input values stored in a txt filecalled input.txt (see an example here):
Program Output
The program determines whether the game has a winner or not. Ifthe game has a winner (the person who remains in the circle aftereveryone else leaves), the program will print out the winner's nameon the screen.
For example, given the list of players and thenumber 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 nowinner, b/c in each pass, two players are out and at the last passno player remain in the circle.
Solution Idea using Circular Linked List
Use the SinglyLinkedList<> class implemented earlier inthe course to construct a circular linkedlist of names (Strings) of the players in the game.Eliminate nodes of players who will be out in each pass. When youreach to only one node in the list, announce the winner!
Hot potato rules:
Program Input
The program gets the following input values stored in a txt filecalled input.txt (see an example here):
Program Output
The program determines whether the game has a winner or not. Ifthe game has a winner (the person who remains in the circle aftereveryone else leaves), the program will print out the winner's nameon the screen.
For example, given the list of players and thenumber 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 nowinner, b/c in each pass, two players are out and at the last passno player remain in the circle.
Solution Idea using Circular Linked List
Use the SinglyLinkedList<> class implemented earlier inthe course to construct a circular linkedlist of names (Strings) of the players in the game.Eliminate nodes of players who will be out in each pass. When youreach to only one node in the list, announce the winner!