Dear java.help:
I just started learning java and was trying to compile some java sourc
from the Javascript World Submission webpage. I know I have loaded m
JDK successfully since I can compile other examples but when I try t
compile the following code, I get several errors.
I typed "javac J1.java(source file name)"
Any feedback is appreciated.
thanks
Banjo
errors:
class Class1 is public, should be declared in a file named Class1.java
cannot resolve symbol
symbol: variable JOptionPane
code:
//*************** *************** ******** // Name: Guess My Name /
Description:Thi s is another very simple java program that will ask yo
for a guess of what my name is, then it will either loop and ask agai
if you got it wrong, or it will continue to the next step. Very simple
for very beginners. It's very clean and well commented though. // By
ryan kit // // // Inputs:Name guesses... // // Returns:If they got th
guess right or wrong // //Assumes:None // //Side Effects:None //Thi
code is copyrighted and has limited warranties. //Please se
[url]http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.3491/lngWId.2/qx/vb/scripts/ShowCode.htm[/url
//for details. //*************** *************** ******** impor
javax.swing.*;
public class Class1
{
public static void main(String[] args)
{
//Declare variables
String myFirstName = "John";
String myLastName = "Smith";
String yourFirstNameGu ess;
String yourLastNameGue ss;
//Declare / define the variables that will count their guesses
int firstNameGuesse s = 5;
int lastNameGuesses = 5;
//Introduce game
JOptionPane.sho wMessageDialog( null, "Welcome to the sUpeR WacK
CrAZy GAme!");
JOptionPane.sho wMessageDialog( null, "... or not, try to guess m
name:");
//Get a guess for the first name
yourFirstNameGu ess = userGuess("Can you guess my first name?"
+ " You have " + (firstNameGuess es)
+ " guesses left.");
//Subtract one from the amount of guesses they have left
firstNameGuesse s--;
//Loop so it asks them for another guess until they guess it o
they run out of guesses
while( !yourFirstNameG uess.equals(myF irstName) &
firstNameGuesse s > 0 )
{
JOptionPane.sho wMessageDialog( null, "Not even close!");
yourFirstNameGu ess = userGuess("Try again, what's my firs
name?"
+ " You have " + (firstNameGuess es)
+ " guesses left for my first name.");
//Subtract one from the amount of guesses they have left
firstNameGuesse s--;
}
//If they got out of the loop because the guesses the righ
name:
if (firstNameGuess es > 0)
{
JOptionPane.sho wMessageDialog( null, "That's right, my name is
+ myFirstName
+ ". Can you guess my last name now?");
//Else is if they got out of the loop because they ran out o
guesses
}else
{
JOptionPane.sho wMessageDialog( null, "Man, you really suck a
this game."
+ " I guess i'll just have to let you go ahead and try t
guess my last name." );
}
//Ask them for a guess for my last name
yourLastNameGue ss = userGuess("What 's my last name? You have "
lastNameGuesses
+ " guesses left.");
//Subtract one form the amount of guesses they have left
lastNameGuesses--;
//Loop so it asks for another guess until they get the name righ
or they run out of guesses
while(!yourLast NameGuess.equal s(myLastName) && lastNameGuesses
0)
{
JOptionPane.sho wMessageDialog( null, "How could you forget m
last name!");
yourFirstNameGu ess = userGuess("Try again, what's my las
name?"
+ " You have " + (lastNameGuesse s)
+ " guesses left for my last name.");
//Subtact one form the amount of guesses they have left
lastNameGuesses--;
}
//Tells what to do if they guesses both first and last name
right
if (lastNameGuesse s > 0 && firstNameGuesse s > 0)
{
JOptionPane.sho wMessageDialog( null, "Nice! You remembered m
last name"
+ ", and my first name!");
//Elseif tells what to do if they got the last name right but th
first name wrong
}else if (lastNameGuesse s > 0 && firstNameGuesse s <= 0)
{
JOptionPane.sho wMessageDialog( null, "Not that bad I guess.
You "
+ "remembered my last name, but you forgot my first name!");
//Else tells what ot do if they got the first name right, but
missed the last name
}else
{
JOptionPane.sho wMessageDialog( null, "You remembered my first
name, but"
+ " you forgot my last name! How could you?");
}
//My little message...
JOptionPane.sho wMessageDialog( null, "Hello there, my name is Ryan
Kit,\n"
+ "and i'm looking for a larger project to work on. I know that
my java\n"
+ "skillz aren't top-o-the-line, but i'm very experinced with
html, css,\n"
+ "javascript , php, mysql, and visual basic. I'm also currently
studying"
+ " perl, and directx.\n\n"
+ "I'd be willing to work for free as a:\n"
+ " programmer\n"
+ " html coder\n"
+ " advanced html coder\n"
+ " technical writer\n"
+ " quality assurance analyst\n"
+ " user interface tester\n"
+ " user interface designer\n"
+ " server installation/maintanence\n"
+ " website maintenance\n"
+ "\nYou can check out some of the work i've done with visual
basic, "
+ "and some other lame java stuff at:\n"
+ "
www.planet-source-code.com.");
System.exit(0);
}
//Method for asking them for a guess, the argument message tells what
the message
//will say, or what it will ask them.
public static String userGuess(Strin g message)
{
String theirGuess;
theirGuess = JOptionPane.sho wInputDialog(nu ll, message);
return theirGuess;
}
}
--
banjo123
------------------------------------------------------------------------
Posted via
http://www.codecomments.com
------------------------------------------------------------------------