Write a program that find the winner of the following gamecalled Hot Potato. Hot potato rules: The person who starts with thepotato passes it to the next person in the circle. After n (givennumber) of passes, the potato "explodes". Whoever is holding thepotato and the person when it explodes and the person (called it x) is out and leaves the circle. Also, the person who passed thepotato to person x right before it explodes will leave the circleas well. The person after them starts with the potato in the nextround, and repeats the same procedure starting at step 1. Whenthere's only one person left in the circle they're the winner.Program Input The program gets the following input values stored ina txt file called input.txt (see an example here): names of playersin a list separated by comma and the number n which shows thenumber of passes before the potato explodes (see step 2). ProgramOutput The program determines whether the game has a winner or not.If the game has a winner (the person who remains in the circleafter everyone else leaves), the program will print out thewinner's name on the screen. For example, given the list of playersand 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 andRoss 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 Aliceand Mary are out! Pass 6: Teddy is the winner! In the case that thenumber of players is even, there will be no winner, b/c in eachpass, two players are out and at the last pass no player remain inthe circle. Solution Idea using Circular Linked List Use theSinglyLinkedList<> class implemented earlier in the course toconstruct a circular linked list of names (Strings) of the playersin the game. Eliminate nodes of players who will be out in eachpass. When you reach to only one node in the list, announce thewinner! Submission Submit a zip file compressing all of the .javafiles for your program.
Please Must Be in JAVA
Write a program that find the winner of the following game called Hot Potato. Hot potato rules: The person who starts wi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am