Write a program that simulates the classic 99 bottles of son

Write a program that simulates the classic \"99 bottles of...\" song using JAVA

Your program should take as input from the user the number of bottles to be simulated and the contents of the bottle. Imagine that you are given a crate with the number of bottles to be used.

Because this is a simulation, your program must first set up the wall, by \'placing\' the bottles up there one at a time (output a line for each bottle placed on the wall). Each time, also output the number of bottles left in the crate as well as the number now on the wall.

Then, the program can \'sing\' the song by outputting a line where it \'takes one down, pass(es) it around\' for each bottle. Assume that the guests, after passing around the bottles, simply throw them on the floor; output the number of bottles on the wall and on the floor.

Sample output:

Solution

// BeerBottle.java
import java.util.Scanner;

public class BeerBottle
{

public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int bottles;
String str;

System.out.print(\"How many bottles are in 1 crate? \");
bottles = sc.nextInt();
System.out.print(\"What\'s in the bottles? \");
str = sc.next();

System.out.println(\"\ Okay. Taking the bottles out of the crate and placing them on the wall!\");
int k = 1;
for (int i = (bottles-1); i >= 0 ;i-- )
{
System.out.println(\"Moving 1 bottle of \" + str + \" to the wall. \" + i + \" in the crate. \" + k + \" on the wall!\");
k++;
}


System.out.println();

for (int i =bottles; i >= 1; i-- )
{
System.out.println(i + \" bottles of \" + str + \" on the wall, \" + i + \" bottles of \" + str + \"; take one down, pass it around, \" + (i-1) + \" bottles of \" + str + \" on the wall! (\" + (bottles-i+1) + \" on the floor)\") ;   
}
}
}

/*
output:


How many bottles are in 1 crate? 5
What\'s in the bottles? milk

Okay. Taking the bottles out of the crate and placing them on the wall!
Moving 1 bottle of milk to the wall. 4 in the crate. 1 on the wall!
Moving 1 bottle of milk to the wall. 3 in the crate. 2 on the wall!
Moving 1 bottle of milk to the wall. 2 in the crate. 3 on the wall!
Moving 1 bottle of milk to the wall. 1 in the crate. 4 on the wall!
Moving 1 bottle of milk to the wall. 0 in the crate. 5 on the wall!

5 bottles of milk on the wall, 5 bottles of milk; take one down, pass it around, 4 bottles of milk on the wall! (1 on the floor)
4 bottles of milk on the wall, 4 bottles of milk; take one down, pass it around, 3 bottles of milk on the wall! (2 on the floor)
3 bottles of milk on the wall, 3 bottles of milk; take one down, pass it around, 2 bottles of milk on the wall! (3 on the floor)
2 bottles of milk on the wall, 2 bottles of milk; take one down, pass it around, 1 bottles of milk on the wall! (4 on the floor)
1 bottles of milk on the wall, 1 bottles of milk; take one down, pass it around, 0 bottles of milk on the wall! (5 on the floor)

*/

Write a program that simulates the classic \
Write a program that simulates the classic \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site