• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!