• Post Reply Bookmark Topic Watch Topic
  • New Topic

Errors compiling BeerSong  RSS feed

 
Joseph Turley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get quite a few errors while trying to compile the BeerSong from the Head First Java book. I copied the text from another person that did the beer song on this forum and it worked as expected. What I can't figure out is why mine is not working when it looks like the text is exactly the same between the two versions. His works, but mine doesn't.

Here is the text and errors that I get:

public class BeerSong
{
public static void main (String[] args)
{
int beerNum = 99;
String word = "bottles";

while (beerNum > 0)
{

if (beerNum == 1)
{
word = "bottle"; // singular, as in ONE bottle.
}
System.out.print1n(beerNum + " " + word + " of beer on the wall");
System.out.print1n(beerNum + " " + word + " of beer");
System.out.print1n("Take one down.");
System.out.print1n("Pass it around.");
beerNum = beerNum - 1;

if (BeerNum > 0)
{ System.out.print1n(beerNum + " " + word + " of beer on the wall");
}
else
{
System.out.print1n("No more bottles of beer on the wall");
} //end else
} //end while loop
} //end main method
} //end class




C:\Users\Ironman\Desktop\Java>javac BottlesOfBeer.java
BottlesOfBeer.java:1: error: class BeerSong is public, should be declared in a f
ile named BeerSong.java
public class BeerSong
^
BottlesOfBeer.java:15: error: cannot find symbol
System.out.print1n(beerNum + " " + word + " of beer on the wall");
^
symbol: method print1n(String)
location: variable out of type PrintStream
BottlesOfBeer.java:16: error: cannot find symbol
System.out.print1n(beerNum + " " + word + " of beer");
^
symbol: method print1n(String)
location: variable out of type PrintStream
BottlesOfBeer.java:17: error: cannot find symbol
System.out.print1n("Take one down.");
^
symbol: method print1n(String)
location: variable out of type PrintStream
BottlesOfBeer.java:18: error: cannot find symbol
System.out.print1n("Pass it around.");
^
symbol: method print1n(String)
location: variable out of type PrintStream
BottlesOfBeer.java:21: error: cannot find symbol
if (BeerNum > 0)
^
symbol: variable BeerNum
location: class BeerSong
BottlesOfBeer.java:22: error: cannot find symbol
{ System.out.print1n(beerNum + " " + word + " of beer on the wall");
^
symbol: method print1n(String)
location: variable out of type PrintStream
BottlesOfBeer.java:26: error: cannot find symbol
System.out.print1n("No more bottles of beer on the wall");
^
symbol: method print1n(String)
location: variable out of type PrintStream
8 errors

C:\Users\Ironman\Desktop\Java>

 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You wrote a 1 instead of a lowercase L in all your println statements. Its println as in "print line".
 
Joseph Turley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes more sense. Thank you for helping me understand. It will now work if I take out "public" from the class file and method.

Do you have any insight on why it doesn't like public? How would I declare that it is public in the file?

This is the error it gives when I keep it in:

C:\Users\Ironman\Desktop\Java>javac BottlesOfBeer.java

C:\Users\Ironman\Desktop\Java>javac BottlesOfBeer.java
BottlesOfBeer.java:1: error: class BeerSong is public, should be declared in a f
ile named BeerSong.java
public class BeerSong
^
1 error

C:\Users\Ironman\Desktop\Java>
 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler is complaining because the name of your class does not match its file name. Your BeerSong class should be in a file named BeerSong.java.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Nice answers, CL.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!