This is homework i been assigned.
1. A popular drinking song has verses of the form:
< n > bottle(s) of < beverage > on the wall,
< n > bottle(s) of < beverage >.
If one of those bottles should happen to fall,
< n − 1 > bottle(s) of < beverage > on the wall.
Write a loop that will print the verses of this song, all the way down to numBottles =
1. If the user is 21 or older, use “beer” as the beverage; otherwise, print “milk.” You
may assume that numBottles and age are already defined as int variables. (4
points)
Hint: To simplify the print statements in your loop, declare a new String variable
named beverage before your loop. Use an if statement to assign a value (either
"milk" or "beer") to beverage based on whether age is less than 21.
This is my code so far.
import javax.swing.*;
void setup () {
}
void draw() {
String beverage; String age = JOptionPane.showInputDialog("What is your age?"); int val= Integer.parseInt(age);//converts string to int int number =99;
if(val >=21){ beverage ="Beer"; println( number+ " of bottles of " + beverage + " on the wall,"); println( number +" bottles of beer,"); println( "If one of those bottles should happen to fall,"); println( number-1 + " bottles of " + beverage + " on the wall"); number--; }else beverage = "Milk"; println(number + "of bottles of " + beverage + " on the wall,"); println(number +" bottles of "+beverage); println("If one of those bottles should happen to fall,"); println(number-1 +" bottles of " +beverage +" on the wall"); number--;