#[Java] Bottle Song Help

30 messages ยท Page 1 of 1 (latest)

rocky flint
#

Instructions
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles.

Note that not all verses are identical.

My code:


    String recite(int startBottles, int takeDown) {

        String [] bottles = {"Ten green bottles hanging on the wall,\n" +
            "Ten green bottles hanging on the wall,\n" +
            "And if one green bottle should accidentally fall,\n" +
            "There'll be nine green bottles hanging on the wall.\n",   "Three green bottles hanging on the wall,\n" +
            "Three green bottles hanging on the wall,\n" +
            "And if one green bottle should accidentally fall,\n" +
            "There'll be two green bottles hanging on the wall.\n"};
        
        return bottles[0];

        

        
    }

}```

It has 7  tests just 1 was solved, what method should I use? to solve this
stiff cloud
#

Pick one of the failing tests. Click on "TEST FAILURE". What is the output of the failing test (using a codeblock and not a screenshot)?

rocky flint
# stiff cloud Pick one of the failing tests. Click on "TEST FAILURE". What is the output of th...
Message: 
expected: 
  "Three green bottles hanging on the wall,
  Three green bottles hanging on the wall,
  And if one green bottle should accidentally fall,
  There'll be two green bottles hanging on the wall.
  "
 but was: 
  "Ten green bottles hanging on the wall,
  Ten green bottles hanging on the wall,
  And if one green bottle should accidentally fall,
  There'll be nine green bottles hanging on the wall.
  " ```

The first is correct, this is the second test
stiff cloud
#

Is there more to the output? Does it show what code was run?

#

Also, which track/language is this?

rocky flint
stiff cloud
#

[Java] Bottle Song Help

rocky flint
# stiff cloud Is there more to the output? Does it show what code was run?
Message: 
expected: 
  "Three green bottles hanging on the wall,
  Three green bottles hanging on the wall,
  And if one green bottle should accidentally fall,
  There'll be two green bottles hanging on the wall.
  "
 but was: 
  "Ten green bottles hanging on the wall,
  Ten green bottles hanging on the wall,
  And if one green bottle should accidentally fall,
  There'll be nine green bottles hanging on the wall.
  "
Exception: org.opentest4j.AssertionFailedError: 
expected: 
  "Three green bottles hanging on the wall,
  Three green bottles hanging on the wall,
  And if one green bottle should accidentally fall,
  There'll be two green bottles hanging on the wall.
  "
 but was: 
  "Ten green bottles hanging on the wall,
  Ten green bottles hanging on the wall,
  And if one green bottle should accidentally fall,
  There'll be nine green bottles hanging on the wall.
  "
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
    at BottleSongTest.lastGenericVerse(BottleSongTest.java:29)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) ``` 

This is all message
stiff cloud
#

The recite() function takes two arguments which are supposed to control the start and end. Your code does not appear to make use of those.

#

The second test checks the results of bottleSong.recite(3, 1)

#

Does that make sense?

rocky flint
stiff cloud
#

Are you new to programming?

rocky flint
#

more or less

stiff cloud
#

Bottle Song probably isn't the best place to start ๐Ÿ™‚ It's not one of the easier exercises

tepid lavaBOT
#

๐Ÿ‘‹๐Ÿผ Hello! We are happy to have you here. Exercism is best suited for people who have some experience in programming. If you are completely new to the topic, exercism might be very challenging. There are many great resources online, that can kickstart your journey in computer science. For a wide understanding, you can try the free CS50x course at Harvard: http://cs50.harvard.edu/x/2023/. If you want to focus on web development you can also try The Odin Projects (free and open source: http://theodinproject.com). It is a long-term commitment, that will guide you to master some projects and will prepare you to show off a nice portfolio in the end. Another interesting resource for web development are the MDN web docs: http://developer.mozilla.org/en-US/docs/Learn

rocky flint
stiff cloud
#

You may want to stick to Easy exercises at the begining

#

Bottle Song uses conditionals, loops, string formatting, lists, etc

rocky flint
stiff cloud
#

Easy exercises are easier. Typically that means more basic. Easy exercises are easier and usually better for beginners. It's good to solve simple problems before trying to solve complex problems.

rocky flint
stiff cloud
#

There are many easy exercises. You may want to solve multiple easy exercises before attempting a medium one.

#

Do you know how to use for loops and conditionals?

#

Did you solve the Lasagna exercise?

rocky flint
rocky flint
stiff cloud
#

Bottle Song requires using for loops. If you don't know how to use those, you want to do that concept first.
Lasagna has functions where you need to use arguments. You would use the arguments in Bottle Song recite() in a similar manner.

rocky flint
#

Ok, thanks for you help