S
Sly166
Guest
help?!! Please!!!? In my Java class I have to make a program!! Please please help!!!!?
In my java class, I have to write a program that prints out the beer song.?
In my java class, I have to write a program that prints out the beer song. I have been working on it for days, and I can't get it to print out the whole song. Here are the instructions for the program:
Write a program that outputs the lyrics for "Ninety Nine Bottles of Beer on the Wall". Your program should print the number of bottles in English, not as a number. For example:
Ninety nine bottles of beer on the wall,
Ninety nine bottles of beer,
Take one down, pass it around,
Ninety eight bottles of beer on the wall.
?
One bottle of beer on the wall,
One bottle of beer,
Take one down, pass it around,
Zero bottles of beer on the wall.
Your program should not use ninety nine different output statements!
Here is my code that I have so far:
Thanks for the help.
class BeerSong
{
/**
* This program outputs the 99 bottles of beer on the wall song.
* A simple loop calls a function that outputs each stanza
* for a particular number of bottles of beer.
* <P>
* We use another function that takes a integer from 0-99 and
* outputs that integer as a word. It uses / and % to extract the
* tens digit and the ones digit so we don't need 100 different
* if-then-else statements.
*/
/**
* Number of bottles that we start out with
*/
int bottles = 99;
public static void printNumInEnglish()
{
private int tens = bottles/10;
private int ones = bottles%10;
String t = new String();
String o = new String();
switch (tens)
{
case 0:
t = "Zero";
break;
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 +" ");
}
/**
* Outputs an entire stanza for n bottles.
*/
public void printStanza(int n) {
// output n in English
printNumInEnglish
;
// account for "one bottle" vs. many "bottles"
if (n == 1) {
System.out.println("bottle of beer on the wall, ");
}
else {
System.out.println("bottles of beer on the wall, ");
}
printNumInEnglish
;
if (n == 1) {
System.out.println("bottle of beer, ");
}
else {
System.out.println("bottles of beer, ");
}
System.out.println("Take one down, pass it around,");
n--;
printNumInEnglish
;
if (n == 1) {
System.out.println("bottle of beer on the wall.");
}
else {
System.out.println("bottles of beer on the wall.");
}
System.out.pri
In my java class, I have to write a program that prints out the beer song.?
In my java class, I have to write a program that prints out the beer song. I have been working on it for days, and I can't get it to print out the whole song. Here are the instructions for the program:
Write a program that outputs the lyrics for "Ninety Nine Bottles of Beer on the Wall". Your program should print the number of bottles in English, not as a number. For example:
Ninety nine bottles of beer on the wall,
Ninety nine bottles of beer,
Take one down, pass it around,
Ninety eight bottles of beer on the wall.
?
One bottle of beer on the wall,
One bottle of beer,
Take one down, pass it around,
Zero bottles of beer on the wall.
Your program should not use ninety nine different output statements!
Here is my code that I have so far:
Thanks for the help.
class BeerSong
{
/**
* This program outputs the 99 bottles of beer on the wall song.
* A simple loop calls a function that outputs each stanza
* for a particular number of bottles of beer.
* <P>
* We use another function that takes a integer from 0-99 and
* outputs that integer as a word. It uses / and % to extract the
* tens digit and the ones digit so we don't need 100 different
* if-then-else statements.
*/
/**
* Number of bottles that we start out with
*/
int bottles = 99;
public static void printNumInEnglish()
{
private int tens = bottles/10;
private int ones = bottles%10;
String t = new String();
String o = new String();
switch (tens)
{
case 0:
t = "Zero";
break;
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 +" ");
}
/**
* Outputs an entire stanza for n bottles.
*/
public void printStanza(int n) {
// output n in English
printNumInEnglish

// account for "one bottle" vs. many "bottles"
if (n == 1) {
System.out.println("bottle of beer on the wall, ");
}
else {
System.out.println("bottles of beer on the wall, ");
}
printNumInEnglish

if (n == 1) {
System.out.println("bottle of beer, ");
}
else {
System.out.println("bottles of beer, ");
}
System.out.println("Take one down, pass it around,");
n--;
printNumInEnglish

if (n == 1) {
System.out.println("bottle of beer on the wall.");
}
else {
System.out.println("bottles of beer on the wall.");
}
System.out.pri