Question

In: Computer Science

Problem 9: Duck Duck Goose JAVA Duck, duck, goose is a child's game where kids sit...

Problem 9: Duck Duck Goose JAVA
Duck, duck, goose is a child's game where kids sit in a circle, facing inward, while another
player, walks around calling each a "duck" until finally calling one a "goose". Given the number
of kids seated in a circle, and the number of ducks called out, determine which child is the
goose.


Facts:
● The player circles the group in clockwise rotation
● Label the children numerically.
○ The first duck called is labeled: child 0
○ To the left of child 0 is child n-1 , where n is the number of children


Input
You are given two positive integer inputs. The first represents the number of kids in the circle.
The second represents the number of ducks that are called before goose.


Output
Print as an integer which child was selected as goose.


Sample Input Sample output
7 15 1
4 4 0
12 6 6


Solutions

Expert Solution

DuckDuckGoose.java

import java.util.Scanner;

public class DuckDuckGoose {
   public static void main(String[] args) {
       // Scanner class object to get the input from user
       Scanner input=new Scanner(System.in);
       System.out.print("Enter the number of kids in the circle: ");
       int numberOfKids=input.nextInt(); // accept the number of kids from user
       System.out.print("Enter the number of ducks called before goose: ");
       int numberOfDucks=input.nextInt(); // accept the number of ducks called before goose
       int gooseSelected;
       // if goose called in first round
       if(numberOfKids>=numberOfDucks)
           gooseSelected=numberOfKids-numberOfDucks;
       else
           // if goose called in other then first round
           gooseSelected=numberOfDucks%numberOfKids;
       // print the child number which was selected as goose
       System.out.println("\nChild number who was selected as goose is "+gooseSelected);
       input.close();
   }
}

Sample run 1

Sample run 2

Sample run 3


Related Solutions

C++ PLEASE In the children’s game, Duck, Duck, Goose, a group of children sit in a...
C++ PLEASE 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...
There is a popular game in the past where children sit on areca leaves and slide...
There is a popular game in the past where children sit on areca leaves and slide down from a higher surface to a lower surface, for example from the top of a small hill. The total mass of the frond and a childern is 67 kg and descends with an initial velocity of 43.3 m / s (assuming there is no friction between the frond and the soil). If then a force slows the movement of the fronds so that...
Telephone is a classic kids game where the first person in line is told a message....
Telephone is a classic kids game where the first person in line is told a message. That person whispers the word to the one next to them, and so on. The last person in line then announces the message as they understand it. Describe this game as a networking protocol in terms of the OSI model. Be specific, and include whatever layers you see as important. How could you change the protocol (and ruin the game) to ensure that the...
Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
Java program that uses binary tree and recursions to implement Tower of Hanoi game where there...
Java program that uses binary tree and recursions to implement Tower of Hanoi game where there can be any amount of disks and there are either 3,4, or 5 pegs to store the disks(# of pegs and disks is manually inputted by user), in Tower of Hanoi game, the object of the game is move all the pieces from the 1st peg to the right most peg or the opposite side. You can place disks on top of each other...
Develop a Java program for this problem where the user inputs an Earth age and the...
Develop a Java program for this problem where the user inputs an Earth age and the program will then display the age on Mercury, Venus, Jupiter, and Saturn. The values for d are listed in the table. Planet d = Approximate Number of Earth Days for This Planet to Travel Around the Sun Mercury 88 Venus 225 Jupiter 4380 Saturn 10767
A variance of Monty Hall Problem. Let's say I am playing a game where there are...
A variance of Monty Hall Problem. Let's say I am playing a game where there are 6 doors, there is a car behind 2 doors and there are goats behind 4 doors. I don't know what is behind the doors but I want a car. Let's say I pick a door at random, so Initially, my chances of winning a car are 1/3. But before I open my door to see if I won, the host of the game opens...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the user to guess four numbers.  Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess, the randomly determined four-digit number, and the amount of points the user has won as follows: No matches 0 points Any one digit matching 5 points Any two digits matching 100 points Any three digits matching 2,000 points All four...
Problem 1. Consider a Cournot game with n > 2 firms, where all firms are identical....
Problem 1. Consider a Cournot game with n > 2 firms, where all firms are identical. Assume the linear demand and cost functions. Solve for the symmetric Nash equilibrium. Find the price at which output is sold in the Nash equilibrium and show that the equilibrium price approaches the unit cost of production, as the number of firms increases arbitrarily. Comment on your result. Payoff function for firm 1: ?(q1, q2,...,qn) = {? - (q1 + q2 + q3 +......
9) Create a java programming where you will enter two numbers and create only one method,...
9) Create a java programming where you will enter two numbers and create only one method, which will return or display addition, substraction, multiplication, division, average and check which number is greater than the other. Everything in one method and call it in main method.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT