Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 34

Thread: Why isn't this code working?

  1. #1
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Why isn't this code working?

    Hello, I am trying to write a program that would output the song "ninety nine bottles of beer on the wall" but for some reason this code isn't working. These are the directions.


    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 CodeMate 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.

    public class BottleSong { here
    /**
    * The number of bottles on which stanzas to be written. The max and min limit to set this is 0 and 99 respectively.
    */
    private int numberOfBottles = 0;
    /**
    * Strings that will be displayed in ones positions
    */
    private String[] onesStrings = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    /**
    * Strings that will be displayed in tens positions
    */
    private String[] tensStrings = {"zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
    /**
    * The special numbers which don't come in a pattern. They are the numbers between 10 and 20
    */
    private String[] tenToTwentyStrings = {"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
    /**
    * Constructor
    * @param numberOfBottles The number of bottles on which stangas to be written
    * @see #numberOfBottles
    */
    public BottleSong(int numberOfBottles){
    setNumberOfBottles(numberOfBottles);
    }
    /**
    * Set appropriate number of bottles according to the conditions
    * @param numberOfBottles
    */
    private void setNumberOfBottles(int numberOfBottles){
    if (numberOfBottles < 0){ // Min should be zero
    this.numberOfBottles = 0;
    }else if (numberOfBottles > 99){ // Max should be ninety nine
    this.numberOfBottles = 99;
    }else{
    this.numberOfBottles = numberOfBottles;
    }
    }
    /**
    * Print the whole poem
    */
    public void printStanza(){
    while (numberOfBottles >= 0){
    //
    printStanza(numberOfBottles);
    numberOfBottles --;
    }
    }
    /**
    * Print stanza for the current number of bottles
    * @param numberOfBottles Current number of bottle count present.
    */
    private void printStanza(int numberOfBottles){
    String numberOfBottlesInText = getTextForNumber(numberOfBottles) + " bottle" + (numberOfBottles != 1 ? "s" : "");
    System.out.println(numberOfBottlesInText + " on the wall\n" + numberOfBottlesInText);
    if (numberOfBottles > 0){// For last bottle, no need to print this line
    System.out.println("\nTake one down, pass it around\n");
    }
    }
    /**
    * Provides the text string for the given number. For example, one for 1.
    * @param numberToBeConverted The number to be converted
    * @return The number in text format
    */
    private String getTextForNumber(int numberToBeConverted){
    String textForNumber = "";
    int tensPart = numberToBeConverted / 10;
    int onesPart = numberToBeConverted % 10;
    if (onesPart == 0){
    textForNumber += tensStrings[tensPart];
    }else{
    if (tensPart > 1){
    textForNumber += (tensStrings[tensPart] + " " + onesStrings[onesPart - 1]);
    }else if (tensPart == 1){
    textForNumber += tenToTwentyStrings[onesPart - 1];
    }else{
    textForNumber += onesStrings[onesPart - 1];
    }
    }
    return textForNumber;
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) { here
    new BottleSong(Integer.parseInt(args[0])).pr… here
    }

    }

    Basically I'm receiving errors on the lines where I put here at the end. Can anyone please tell me what's wrong with my code?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Why isn't this code working?

    When posting code, please use the highlight tags. Unformatted code is very hard to read. Also, post the full text of any error messages or stack traces you receive.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    Quote Originally Posted by KevinWorkman View Post
    When posting code, please use the highlight tags. Unformatted code is very hard to read. Also, post the full text of any error messages or stack traces you receive.
    public class BottleSong {
    /**
    * The number of bottles on which stanzas to be written. The max and min limit to set this is 0 and 99 respectively.
    */
    private int numberOfBottles = 0;
    /**
    * Strings that will be displayed in ones positions
    */
    private String[] onesStrings = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    /**
    * Strings that will be displayed in tens positions
    */
    private String[] tensStrings = {"zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
    /**
    * The special numbers which don't come in a pattern. They are the numbers between 10 and 20
    */
    private String[] tenToTwentyStrings = {"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
    /**
    * Constructor
    * @param numberOfBottles The number of bottles on which stangas to be written
    * @see #numberOfBottles
    */
    public BottleSong(int numberOfBottles){
    setNumberOfBottles(numberOfBottles);
    }
    /**
    * Set appropriate number of bottles according to the conditions
    * @param numberOfBottles
    */
    private void setNumberOfBottles(int numberOfBottles){
    if (numberOfBottles < 0){ // Min should be zero
    this.numberOfBottles = 0;
    }else if (numberOfBottles > 99){ // Max should be ninety nine
    this.numberOfBottles = 99;
    }else{
    this.numberOfBottles = numberOfBottles;
    }
    }
    /**
    * Print the whole poem
    */
    public void printStanza(){
    while (numberOfBottles >= 0){
    //
    printStanza(numberOfBottles);
    numberOfBottles --;
    }
    }
    /**
    * Print stanza for the current number of bottles
    * @param numberOfBottles Current number of bottle count present.
    */
    private void printStanza(int numberOfBottles){
    String numberOfBottlesInText = getTextForNumber(numberOfBottles) + " bottle" + (numberOfBottles != 1 ? "s" : "");
    System.out.println(numberOfBottlesInText + " on the wall\n" + numberOfBottlesInText);
    if (numberOfBottles > 0){// For last bottle, no need to print this line
    System.out.println("\nTake one down, pass it around\n");
    }
    }
    /**
    * Provides the text string for the given number. For example, one for 1.
    * @param numberToBeConverted The number to be converted
    * @return The number in text format
    */
    private String getTextForNumber(int numberToBeConverted){
    String textForNumber = "";
    int tensPart = numberToBeConverted / 10;
    int onesPart = numberToBeConverted % 10;
    if (onesPart == 0){
    textForNumber += tensStrings[tensPart];
    }else{
    if (tensPart > 1){
    textForNumber += (tensStrings[tensPart] + " " + onesStrings[onesPart - 1]);
    }else if (tensPart == 1){
    textForNumber += tenToTwentyStrings[onesPart - 1];
    }else{
    textForNumber += onesStrings[onesPart - 1];
    }
    }
    return textForNumber;
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) { here
    new BottleSong(Integer.parseInt(args[0])).pr… here
    }

    } here
    Ok this is what I have so far.

    The problem lies in the last 3 lines. Where I wrote "here" that's where the red question mark pops up indicating an error. Also, when I try to run it why does it say that assignment.pkg4.pkg1.Assignment41 class wasn't found in assignment 4.1 project? It's telling me that there is no main class found. Why is that?

    package assignment.pkg4.pkg1;

    /**
    *
    *
    */
    public class Assignment41 {

    /**
    * @param args the command line arguments
    */
    This is what I have exactly before the code I posted. This is on top of the "public class BottleSong {" and so on and so forth. If you can help me with this that would be great. Thank you.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Why isn't this code working?

    You still haven't properly posted the code (quote tags are not highlight tags), and we can't see your project setup (directory setup, etc). What are your compiler errors, exactly? If you don't know how to see them in our IDE, I recommend compiling via the command prompt.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    Please use code tags, not quote tags.

    Where is the error message text? Can you compile the source with javac and post the error messages from the compiler?

  6. #6
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    For the public static void main thing it says "illegal static declaration in inner class assignment.pkg4.pkg1.Assignment41.BottleSong. Modifier 'static' is only allowed in constant variable declarations."

    For new BottleSong (Integer.parseInt (args[0])).pr... it says "non-static variable this cannot be referenced from a static context. Not a statement. Illegal character: \8230."

    For the last brace it says "reached end of file while parsing."

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Why isn't this code working?

    Like I said, you'll have to provide an SSCCE (not your whole program, not just random snippets of code) that demonstrates the problem. Otherwise we're just guessing. And please use the highlight tags!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    How do I do that? I don't see what the problem is. I copied and pasted everything from my IDE to here. I'm using NetBeans if that matters.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    Can you change the tags around your code from quote to code to make your code readable?

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Why isn't this code working?

    You've posted a bunch of unformatted code, which is very hard to read. You also have not posted your actual code, as package declarations, inner classes, etc are not shown despite them being a part of your problem. Please post an SSCCE inside highlight tags. Make it easier for people to help you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    Can anyone please help me?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    Are you having problems doing this?
    Can you change the tags around your code from quote to code to make your code readable?

    Your code is not readable the way it is posted.

  13. #13
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    public class BottleSong {

    private int numberOfBottles = 0;

    private String[] onesStrings = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    private String[] tensStrings = {"zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};

    private String[] tenToTwentyStrings = {"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};

    public BottleSong(int numberOfBottles){
    setNumberOfBottles(numberOfBottles);
    }

    private void setNumberOfBottles(int numberOfBottles){
    if (numberOfBottles < 0){
    this.numberOfBottles = 0;
    }else if (numberOfBottles > 99){
    this.numberOfBottles = 99;
    }else{
    this.numberOfBottles = numberOfBottles;
    }
    }

    public void printStanza(){
    while (numberOfBottles >= 0){
    //
    printStanza(numberOfBottles);
    numberOfBottles --;
    }
    }

    private void printStanza(int numberOfBottles){
    String numberOfBottlesInText = getTextForNumber(numberOfBottles) + " bottle" + (numberOfBottles != 1 ? "s" : "");
    System.out.println(numberOfBottlesInText + " on the wall\n" + numberOfBottlesInText);
    if (numberOfBottles > 0){// For last bottle, no need to print this line
    System.out.println("\nTake one down, pass it around\n");
    }
    }

    private String getTextForNumber(int numberToBeConverted){
    String textForNumber = "";
    int tensPart = numberToBeConverted / 10;
    int onesPart = numberToBeConverted % 10;
    if (onesPart == 0){
    textForNumber += tensStrings[tensPart];
    }else{
    if (tensPart > 1){
    textForNumber += (tensStrings[tensPart] + " " + onesStrings[onesPart - 1]);
    }else if (tensPart == 1){
    textForNumber += tenToTwentyStrings[onesPart - 1];
    }else{
    textForNumber += onesStrings[onesPart - 1];
    }
    }
    return textForNumber;
    }

    public static void main(String[] args) { here
    new BottleSong(Integer.parseInt(args[0])).pr… here
    }

    } here
    Ok is this readable now?

    Basically the only problem I have is the line that says, "new BottleSong(Integer.parseInt(args[0])).pr… ". It's saying illegal character: \8230 and that it's not a statement. I fixed the others by making BottleSong the only public class.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    No, there is no indentation. All the lines start in column 1. Nested code should be indented.
    Please use code tags.

    Where did you get this statement from?
        BottleSong(Integer.parseInt(args[0])).pr

    Statements should end with a ;
    Last edited by Norm; March 12th, 2012 at 12:41 PM.

  15. #15
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    So you're saying I should remove that statement? I did and when I ran it I got nothing. Is the code supposed to be working?

  16. #16
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Why isn't this code working?

    Quote Originally Posted by tai8 View Post
    So you're saying I should remove that statement? I did and when I ran it I got nothing. Is the code supposed to be working?
    What would you expect your code to do with that statement removed? Norm was simply pointing out that you had a syntax error on that line.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  17. #17
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    So no one knows? I'm not sure why it isn't running...

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    What isn't running? Add a call to println to print out a message the first thing in the main() method. If it prints then you will know that the program is running.

  19. #19
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    How do I do that? I'm sorry for asking these questions, I'm a beginner with this and really don't know...

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    Which don't you know?
    add a line of code first thing in the main() method
    printing a message?

    Your code has several statements that print output using println. For example:
       System.out.println("\nTake one down, pass it around\n");

    Change the message and add it to the main() method

  21. #21
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    So am I supposed to just add this: "System.out.println("\nTake one down, pass it around\n");" after the public static void main(String[] args) { ? I did and when I ran it it outputted Take one down, pass it around. That's all it outputted.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    That shows that your program is running.
    Now if you want it to execute other parts of the program you will have to add code to do that.
    One way is to create an instance of the class that the main() method is in and call one of its methods.

  23. #23
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    Quote Originally Posted by Norm View Post
    That shows that your program is running.
    Now if you want it to execute other parts of the program you will have to add code to do that.
    One way is to create an instance of the class that the main() method is in and call one of its methods.
    I thought I already did do that. How do I create an instance of the class and call one of its methods?

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why isn't this code working?

    Did you skip the first couple of chapters of your textbook?
    Creating an instance and calling a method are very basic concepts.
    Here is a tutorial that you should read:
    Trail: Learning the Java Language: Table of Contents (The Java™ Tutorials)

  25. #25
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Why isn't this code working?

    Ok I tried something completely different. This is my completely different code.


    public class BottleSong { 
     private int bottles =99;
    public BottleSong(int n)
    {
    bottles = n;
    }
    public void printNumInEnglish(int n)
    {
     int tens = bottles/10;
     
                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 +" ");
    }
     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]);
     
            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("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();
     
        }
     
     
     
    }


    When I run it it works however it plays something like this:

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

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

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

    And so on and so forth. How do I get the code to output so it would be like:

    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.

    Ninety eight bottles of beer on the wall,
    Ninety eight bottles of beer,
    Take one down, pass it around,
    Ninety seven bottles of beer on the wall.

    all the way down to 0?

    If someone can help me with I would give a million thanks.
    Last edited by tai8; March 12th, 2012 at 03:07 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. I don't get why this code isn't working
    By tai8 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: February 20th, 2012, 12:38 PM
  2. Code working only on ide
    By xeyos in forum Java Networking
    Replies: 0
    Last Post: November 17th, 2011, 05:40 PM
  3. Simple code, cant get it working.
    By Malmen in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 8th, 2011, 03:28 PM
  4. My code is not working
    By mike2452 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 9th, 2011, 06:17 AM
  5. Getting code working with gui
    By Nostromo in forum AWT / Java Swing
    Replies: 2
    Last Post: March 21st, 2011, 09:34 PM