Write a Java Program With Pseudo Code that simulates a game
Write a Java Program (With Pseudo Code) that simulates a game of Duck, Duck, Goose. In the children’s game, Duck, Duck, Goose, a group of children sit in a circle. One of them is elected “it” and that person walks around the outside of the circle. The person who is “it” pats each child on the head, saying “Duck” each time, until randomly reaching a child that the “it” person identifies as “Goose.” At this point there is a mad scramble, as the “Goose” and the “it” person race around the circle. Whoever returns to the Goose’s former place first gets to remain in the circle. The loser of this race is the “it” person for the next round of play. The game continues like this until the children get bored or an adult tells them it’s snack time. Write software that simulates a game of Duck, Duck, Goose.
Solution
Algorithm:
1. Input the number of players of the game and insert all of them to the circle
2. Input the total number of rounds of the simulation.
3. Output the it player .
Java Program :
package Game;
import java.util.*;
import javax.swing.JOptionPane;
public class Game
{
public static void main(String[] args)
{
String cycles = JOptionPane.showInputDialog(\"Enter number of cycles\");
int Cycle = Integer.parseInt(cycles);
String players = JOptionPane.showInputDialog(\"Enter number of players\");
int playersName = Integer.parseInt(players);
ArrayList al = new ArrayList (playersName);
int count = 0;
while(count < playersName)
{
count++;
al.add(\"Player Number \\t\" + count);
System.out.println(al);
}
int addition = 0;
int counter = 0;
counter++;
while(counter < 999)
{
addition++;
if(addition == Cycle)
{
al.remove(1);
if(al.size() == 1)
{
break;
}
}
if (addition > Cycle)
{
addition = 0;
}
}
System.out.println(al);
}
}
Output:
Enter number of cycles
3
Enter number of players
3
[Player Number 1]
[Player Number 1, Player Number 2]
[Player Number 1, Player Number 2, Player Number 3]
[Player Number 1]
BUILD SUCCESSFUL (total time: 10 seconds)

