public class BottleSong {
private int bottles = 0;
public BottleSong(int n)
{
bottles = n;
}
public void printNumInEnglish(int n)
{
int tens = n/10;
int ones = n%10;
String t = new String();
String o = new String();
switch (tens)
{
case 1:
switch (ones)
{
case 0:
o = "Ten";
break;
case 1:
o = "Eleven";
break;
case 2:
o = "Twelve";
break;
case 3:
o = "Thirteen";
break;
case 4:
o = "Fourteen";
break;
case 5:
o = "Fifteen";
break;
case 6:
o = "Sixteen";
break;
case 7:
o = "Seventeen";
break;
case 8:
o = "eighteen";
break;
case 9:
o = "nineteen";
break;
}
case 2:
t = "Twenty";
break;
case 3:
t = "Thirty";
break;
case 4:
t = "Forty";
break;
case 5:
t = "Fifty";
break;
case 6:
t = "Sixty";
break;
case 7:
t = "Seventy";
break;
case 8:
t = "Eighty";
break;
case 9:
t = "Ninety";
break;
}
if (tens != 1)
{
switch (ones)
{
case 1:
o = "One";
break;
case 2:
o = "Two";
break;
case 3:
o = "Three";
break;
case 4:
o = "Four";
break;
case 5:
o = "Five";
break;
case 6:
o = "Six";
break;
case 7:
o = "Seven";
break;
case 8:
o = "Eight";
break;
case 9:
o = "Nine";
break;
}
}
System.out.print(t + " " + o + " ");
}
public void printStanza(int n)
{
String [] numbers = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen" };
String [] tens = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
if(n < 20)
System.out.println(numbers[n-1]);
else
if(n % 10 == 0)
System.out.println(tens[(n/10)-2]);
else
System.out.println(tens[(n/10)-2] + " " + numbers[n%10]);
printNumInEnglish(n);
if (n == 1) {
System.out.println("one bottle of beer on the wall, ");
}
else {
System.out.println("bottles of beer on the wall, ");
}
printNumInEnglish(n);
if (n == 1) {
System.out.println("one bottle of beer, ");
}
else {
System.out.println("bottles of beer, ");
}
System.out.println("Take one down, pass it around,");
n--;
printNumInEnglish(n);
if (n == 1) {
System.out.println("bottle of beer on the wall.");
}
else {
System.out.println("bottles of beer on the wall.");
}
System.out.println();
}
public void printSong() {
// Loop from 99 down to 0
for (int num = bottles; num > 0; num--) {
printStanza(num);
}
}
public static void main(String[] args) {
BottleSong bs = new BottleSong(99);
bs.printSong();
}
}