• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Beer Song

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to write a program to display the lyrics to the beer song. I can't get my program to compile and I dont think it has everything it needs either. Thanks for the help. 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!

Design your program with a class named BeerSong whose constructor takes an integer parameter that is the number of bottles of beer that are initially on the wall. If the parameter is less than zero, set the number of bottles to zero. Similarly, if the parameter is greater than 99, set the number of beer bottles to 99. Then make a public method called printSong that outputs all stanzas from the number of bottles of beer down to zero. Add any additional private methods you find helpful.

In this exercise, you should implement a constructor for the BeerSong class that takes a single parameter of type int that specifies the number of bottles of beer. You should also implement a method named printNumInEnglish that takes a single int parameter specifying a number to be printed (in English) to the console.

Here is my code so far:



Here are my errors:

The method exit(int) in the type System is not applicable for the arguments ()
The method printNumInEnglish() in the type BeerSong is not applicable for the arguments (int)
The method printNumInEnglish() in the type BeerSong is not applicable for the arguments (int)
The method printNumInEnglish() in the type BeerSong is not applicable for the arguments (int)
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your compilation errors are simple typos:

System.exit(int x) requires an error code to be passed. System.exit(void) doesn't exist. So just add a parameter to System.exit(). I use 0 frequently, though other numbers should work equally well.

Your function printNumInEnglish() doesn't take a parameter, but you pass a parameter to it three times. You'll have to iron this out on your own, in the best interest of your program.

That should get it to compile.
 
Edicius Rogers
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much for helping. I got all my errors fixed and when I compile and run it, it just loops: (see below) 99 times

Ninety Nine bottle of beer on the wall,
Ninety Nine bottle of beer,
Take one down, pass it around,
Ninety Nine bottles of beer on the wall.

To fix my errors, I added a zero: System.exit(0); and I took the n out of: printNumInEnglish(n)
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, look at what it's doing. You have a for loop in which a new variable (num) is defined. But printNumInEnglish is using your static bottles variable, which is never altered. You need to change that value, or you need to modify your code so that printNumInEnglish uses a parameter passed to it.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if you read the specification you will see that Jeremy's second suggestion is the way to go
You should also implement a method named printNumInEnglish that takes a single int parameter specifying a number to be printed (in English) to the console.
 
reply
    Bookmark Topic Watch Topic
  • New Topic