aspose file tools*
The moose likes Beginning Java and the fly likes Beer Song(I checked the forums for previous posts) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Beer Song(I checked the forums for previous posts)" Watch "Beer Song(I checked the forums for previous posts)" New topic
Author

Beer Song(I checked the forums for previous posts)

S Kanth
Greenhorn

Joined: Nov 05, 2012
Posts: 7
Hi everyone, I've already checked the forums for the beer song flaw. There's a flaw according to the book Head First Java. Please check if I did it right. I can't seem to spot the flaw or I think I did correct it.
The actual code


What I did:


I have run them both, the only change I noticed was that the extra line vanished and I think what I did is correct, please help.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hi, and welcome to the Ranch!

S Kanth wrote:I think what I did is correct, please help.


So you ran it and it produced the correct output? If so what do you need help with?

If it did not produce the correct results, then you must know that what you did isn't correct. But again, what specific problem are you having?
S Kanth
Greenhorn

Joined: Nov 05, 2012
Posts: 7
I'm not sure if it is correct or not. I did run it, the problem is I'm not sure if I had solved the small flaw as mentioned in the book.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

S Kanth wrote:I'm not sure if it is correct or not.


Meaning you're not sure if the output is correct or not?

It should be:

99 bottles of beer on the wall
99 bottles of beer
take one down
pass it around
98 bottles of beer on the wall

98 bottles of beer on the wall
98 bottles of beer
... and so on ...

Down to
1 bottle of beer on the wall
1 bottle of beer
take one down
pass it around
no more bottles of beer on the wall


Is this what you get?
S Kanth
Greenhorn

Joined: Nov 05, 2012
Posts: 7
What I get is like this

99 bottles of beer on the wall
99 bottles of beer.
Take one down.
Pass it around.
98 bottles of beer on the wall
98 bottles of beer.
Take one down.
Pass it around.
......so on
.....
1 bottle of beer on the wall
1 bottle of beer.
Take one down.
Pass it around.
No more bottles of beer on the wall

99 bottles of beer on the wall
99 bottles of beer
take one down
pass it around
98 bottles of beer on the wall

98 bottles of beer on the wall
98 bottles of beer

Meaning that I should get "98 bottles of beer on the wall", that line twice for whatever the number is?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

S Kanth wrote:
Meaning that I should get "98 bottles of beer on the wall", that line twice for whatever the number is?


I don't know what the assignment says, but each verse of the actual song, as I learned it, is


So, according to that, yes, you would see all the non-fencepost numbers with "...bottles of beer on the wall" twice in a row--once at the end of a verse as N - 1, and immediately after that at the beginning of the next verse as the new N.
S Kanth
Greenhorn

Joined: Nov 05, 2012
Posts: 7


This is the code, the output I'm getting at the last lines as
1 bottles of beer on the wall
1 bottle of beer on the wall
1 bottle of beer.
Take one down.
Pass it around.
No more bottles of beer on the wall


I think 1 bottles is the flaw, how do I get about that?
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 75

What I would do is move:

outside of the while loop.


Then put the boolean expression:

in place of


Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
S Kanth
Greenhorn

Joined: Nov 05, 2012
Posts: 7


Take a look at that AJ, I am getting the output correct for all except for the last lines where in I'm getting
2 bottles of beer on the wall
2 bottles of beer.
Take one down.
Pass it around.
1 bottles of beer on the wall -----> that's the one part where it should be bottle and not bottles, you can't move in place of the greater than sign. Please check once again.

1 bottle of beer on the wall
1 bottle of beer.
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 75

Why can't you move


I did and apart from me missing a case, it works.

I looked over it again and forgot to say that I would add another "else if" because there is another case in regards to beerNum.
S Kanth
Greenhorn

Joined: Nov 05, 2012
Posts: 7
I got it, thanks folk for helping me. I was trying to tweak the code and see a few possible outputs. Trial and error method basically.
This is what I did.
You have to place the

Just before


Like this

S Kanth
Greenhorn

Joined: Nov 05, 2012
Posts: 7
Oh sorry, Aj, you did suggest the same thing that I did finally. Just a minor misunderstanding I suppose. "In place of" is what you told, so I assumed you wanted me to replace it.
 
 
subject: Beer Song(I checked the forums for previous posts)