JavaRanch » Java Forums »
Java »
Beginning Java
| 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!!
|
 |
 |
|
|
subject: PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...)
|
|
|
|