• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic