This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...)" Watch "PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...)" New topic
Author

PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...)

Siki Rikishi
Greenhorn

Joined: Dec 30, 2003
Posts: 14
Sorry. I've typed in PhraseOMatic from Head First Java and I'm getting errors. First, I'll paste what I typed:
public class PhraseOMatic {
public static void main (String[] args) {

// make 3 sets of words to choose from. Add your own!
String[] wordListOne = {"24/7", "multi-Tier", "30,000 foot", "B-to-B", "win-win", "front-end", "Web-based", "pervasive", "smart", "six-sigma", critical-path", "dynamic"};
String[] wordListTwo = {"empowered", "sticky", "value-added", "oriented", "centric", "distributed", "clustered", "branded", "outside-the-box", "positioned", "networked", "focused", "leveraged", "aligned", "targeted", "shared", "cooperative", "accelerated"};
String[] wordListThree = {"process", "tipping-point", "solution", "architecture", "core compentency", "strategy", "mindshare", "portal", "space", "vision", "paradigm", "mission"};
// find out how many words are in each list
int oneLength = wordListOne.length;
int twoLength = wordListTwo.length;
int threeLength = wordListThree.length;
// generate three random numbers
int rand1 = (int) (Math.random() * oneLength);
int rand2 = (int) (Math.random() * twoLength);
int rand3 = (int) (Math.random() * threeLength);
// now build a phrase
String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
// print out the phrase
System.out.println ("What we need is a " + phrase);
}
}
I did this in Notepad and I didn't hit the return key per the book(the wordlists are all on one line).
Here's the errors that I'm getting:
C:\>javac PhraseOMatic.java
PhraseOMatic.java:5: '}' expected
String[] wordListOne = {"24/7", "multi-Tier", "30,000 foot", "B-to-B", "
win-win", "front-end", "Web-based", "pervasive", "smart", "six-sigma", critical-
path", "dynamic"};

^
PhraseOMatic.java:5: unclosed string literal
String[] wordListOne = {"24/7", "multi-Tier", "30,000 foot", "B-to-B", "
win-win", "front-end", "Web-based", "pervasive", "smart", "six-sigma", critical-
path", "dynamic"};

^
PhraseOMatic.java:5: cannot resolve symbol
symbol : variable critical
location: class PhraseOMatic
String[] wordListOne = {"24/7", "multi-Tier", "30,000 foot", "B-to-B", "
win-win", "front-end", "Web-based", "pervasive", "smart", "six-sigma", critical-
path", "dynamic"};
^
PhraseOMatic.java:5: cannot resolve symbol
symbol : variable path
location: class PhraseOMatic
String[] wordListOne = {"24/7", "multi-Tier", "30,000 foot", "B-to-B", "
win-win", "front-end", "Web-based", "pervasive", "smart", "six-sigma", critical-
path", "dynamic"};

^
PhraseOMatic.java:5: incompatible types
found : int
required: java.lang.String
String[] wordListOne = {"24/7", "multi-Tier", "30,000 foot", "B-to-B", "
win-win", "front-end", "Web-based", "pervasive", "smart", "six-sigma", critical-
path", "dynamic"};
^
PhraseOMatic.java:11: cannot resolve symbol
symbol : variable wordListTwo
location: class PhraseOMatic
int twoLength = wordListTwo.length;
^
PhraseOMatic.java:20: cannot resolve symbol
symbol : variable wordListTwo
location: class PhraseOMatic
String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wo
rdListThree[rand3];
^
7 errors
I've gone through each (starting at the top) and I feel like I DO have what it's asking for so I'm confused! I've checked the erratas but there's no mention of this. Thanks in advance!
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Spotted one of your errors:
Where you display your string array wordListOne, take a look at the string "critical-path" - you are missing the open quotes on that string.
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
I just copied your code, made the following change, and it built fine. I think the missing parenthasis was the only problem you had.

Hope that helps!
Siki Rikishi
Greenhorn

Joined: Dec 30, 2003
Posts: 14
It worked! It was the missing quotation mark!! Sigh...
Thanks SOOOOO much!! Any advice on getting the most out of this book? This is a GREAT book, by the way! Good job!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...)