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:This 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 yourFirstNameGuess;
String yourLastNameGuess;
//Declare / define the variables that will count their guesses
int firstNameGuesses = 5;
int lastNameGuesses = 5;
//Introduce game
JOptionPane.showMessageDialog(null, "Welcome to the sUpeR WacK
CrAZy GAme!");
JOptionPane.showMessageDialog(null, "... or not, try to guess m
name:");
//Get a guess for the first name
yourFirstNameGuess = userGuess("Can you guess my first name?"
+ " You have " + (firstNameGuesses)
+ " guesses left.");
//Subtract one from the amount of guesses they have left
firstNameGuesses--;
//Loop so it asks them for another guess until they guess it o
they run out of guesses
while( !yourFirstNameGuess.equals(myFirstName) &
firstNameGuesses > 0 )
{
JOptionPane.showMessageDialog(null, "Not even close!");
yourFirstNameGuess = userGuess("Try again, what's my firs
name?"
+ " You have " + (firstNameGuesses)
+ " guesses left for my first name.");
//Subtract one from the amount of guesses they have left
firstNameGuesses--;
}
//If they got out of the loop because the guesses the righ
name:
if (firstNameGuesses > 0)
{
JOptionPane.showMessageDialog(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.showMessageDialog(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
yourLastNameGuess = 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(!yourLastNameGuess.equals(myLastName) && lastNameGuesses
0)
{
JOptionPane.showMessageDialog(null, "How could you forget m
last name!");
yourFirstNameGuess = userGuess("Try again, what's my las
name?"
+ " You have " + (lastNameGuesses)
+ " 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 (lastNameGuesses > 0 && firstNameGuesses > 0)
{
JOptionPane.showMessageDialog(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 (lastNameGuesses > 0 && firstNameGuesses <= 0)
{
JOptionPane.showMessageDialog(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.showMessageDialog(null, "You remembered my first
name, but"
+ " you forgot my last name! How could you?");
}
//My little message...
JOptionPane.showMessageDialog(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(String message)
{
String theirGuess;
theirGuess = JOptionPane.showInputDialog(null, message);
return theirGuess;
}
}
--
banjo123
------------------------------------------------------------------------
Posted via
http://www.codecomments.com
------------------------------------------------------------------------