Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prints the first few verses of the traveling song \"One Hun

ID: 3820431 • Letter: W

Question

Write a program that prints the first few verses of the traveling song "One Hundred Bottles of Beer." Use a loop such that each prints one verse. Read the number of verses to print from the user. Validate the input The following are the first two verses of the so 100 bottles of beer on the wall 100 bottles of beer If one of those bottles should happen to fall 99 bottles of beer on the wall 99 bottles of beer on the wall 99 bottles of beer If one of those bottles should happen to fall 98 bottles of beer on the wall A scanner object for input A variable to store the number of verses Two loops: 1. One to perform input validation 2. The other to adjust the verses for each iteration Comments for appropriate documentation A sample of the output is shown below: How many verses (1 to 100)? -3 How many verses (1 to 100)? 3 100 bottles of beer on the wall. 100 bottles of beer. If one of those bottles should happen to fall 99 bottles of beer on the wall. 99 bottles of beer on the wall. 99 bottles of beer. If one of those bottles should happen to fall 98 bottles of beer on the wall. 98 bottles of beer on the wall. 98 bottles of beer. If one of those bottles should happen to fall

Explanation / Answer

BottlesOfBeerOnTheWall.java

import java.util.Scanner;

public class BottlesOfBeerOnTheWall {

   public static void main(String[] args) {
       //Declaring variables
       int num;
       int bottles =100;
      
       //Scanner object is used to get the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
      
       /* This loop continues to execute until
       * the user enters a positive number
       * */
       do
       {
           //Getting the number entered by the user
           System.out.print("How many Verser :");
           num=sc.nextInt();
       }while(num<0);

      
       //This for loop will display the song each verse
       for(int i=1;i<=num;i++)
       {
           System.out.println(" "+bottles+" bottles of beer on the wall.");
           System.out.println(bottles+" bottles of beer.");
           System.out.println("If one of those bottles should happen to fall.");
           System.out.println((--bottles)+" bottles of beer on the wall.");
       }

   }

}

___________________

Output:

How many Verser :-3
How many Verser :3

100 bottles of beer on the wall.
100 bottles of beer.
If one of those bottles should happen to fall.
99 bottles of beer on the wall.

99 bottles of beer on the wall.
99 bottles of beer.
If one of those bottles should happen to fall.
98 bottles of beer on the wall.

98 bottles of beer on the wall.
98 bottles of beer.
If one of those bottles should happen to fall.
97 bottles of beer on the wall.

____________Thank You

Please rate me well.If you are satisfied.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote