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

Follow the instructions given below and keep the program as simple as possible:

ID: 3793578 • Letter: F

Question

Follow the instructions given below and keep the program as simple as possible:

Bottles of Beer on the wall Write a program that prints the first few verses of the traveling song "One Hundred Bottles of Beer." Use a loop such 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 song: 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 You will need: A scanner object for input A variable to store the number of verses Two loops: One to perform input validation 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 97 bottles of beer on the wall.

Explanation / Answer

import java.util.*;

class Employees
{
   public static void main (String[] args)
   {
       Scanner scan = new Scanner(System.in);
       System.out.println("How many verses (1-100) ?");
       int verses = scan.nextInt();
       if(verses < 0)   //validation check for verses,should not be less than 0
       {
           System.out.println("How many verses (1-100) ?"); //if negative input verses again
           verses = scan.nextInt();
       }
       int bottles = 100;
  
       System.out.println();
      
       for(int i=0;i<verses;i++) // loop will execute verses number of times
       {
           System.out.println((bottles-i) +" bottles of beer on the wall.");
           System.out.println((bottles-i) +" bottles of beer.");
           System.out.println("If one of those bottles should happen to fall.");
           System.out.println((bottles-(i+1)) +" bottles of beer on the wall.");
          
           System.out.println();
       }
   }
}

output: