473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

problem with compile


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
------------------------------------------------------------------------

Jul 17 '05 #1
1 2222

"banjo123" <ba*************@mail.codecomments.com> wrote in message
news:1103139200.f237ce927b5338871b71d1787cfd95ff@t ng...

Dear java.help:

I just started learning java and was trying to compile some java source
from the Javascript World Submission webpage. I know I have loaded my
JDK successfully since I can compile other examples but when I try to
compile the following code, I get several errors.

I typed "javac J1.java(source file name)" *************
The name of the file needs to be the same as the class if the class is
public
the first line in the error messages tells the true story.
(You tried to compile "J1.java" and the file should be "Class1.java"
************** 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 you
for a guess of what my name is, then it will either loop and ask again
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 the
guess right or wrong // //Assumes:None // //Side Effects:None //This
code is copyrighted and has limited warranties. //Please see
http://www.Planet-Source-Code.com/xq...s/ShowCode.htm //for details. //************************************** import
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 WacKY
CrAZy GAme!");
JOptionPane.showMessageDialog(null, "... or not, try to guess my
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 or
they run out of guesses
while( !yourFirstNameGuess.equals(myFirstName) &&
firstNameGuesses > 0 )
{
JOptionPane.showMessageDialog(null, "Not even close!");
yourFirstNameGuess = userGuess("Try again, what's my first
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 right
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 of
guesses
}else
{
JOptionPane.showMessageDialog(null, "Man, you really suck at
this game."
+ " I guess i'll just have to let you go ahead and try to
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 right
or they run out of guesses
while(!yourLastNameGuess.equals(myLastName) && lastNameGuesses >
0)
{
JOptionPane.showMessageDialog(null, "How could you forget my
last name!");
yourFirstNameGuess = userGuess("Try again, what's my last
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 names
right
if (lastNameGuesses > 0 && firstNameGuesses > 0)
{
JOptionPane.showMessageDialog(null, "Nice! You remembered my
last name"
+ ", and my first name!");

//Elseif tells what to do if they got the last name right but the
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
------------------------------------------------------------------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.807 / Virus Database: 549 - Release Date: 12/7/2004
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jesper | last post by:
Hi I am currently following the tutorial from IBM (http://www-106.ibm.com/developerworks/xml/edu/x-dw-xjaxb-i.html) I have three problems at the moment. 1. It says else where that when the...
3
by: Christopher M. Lusardi | last post by:
Hello, THE PROBLEM ----------- If I compile parts of my program with CC, and C, using extern "C" as appropriate it compiles without any errors, but it does a segmentation fault when I run the...
6
by: Michael Höing | last post by:
Hi, I tried to compile the following : http://www.almaden.ibm.com/software/quest/Resources/datasets/data/assoc.gen.tar.Z from...
2
by: Ivan Riis Nielsen | last post by:
Hello group, I've just stumbled upon a compile-error which I don't understand. I was hoping someone can explain to me why my code is a problem. I'm implementing a somewhat complex class...
5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
2
by: AlexS | last post by:
Hello, I have error when reading schema using XmlSchema. Read and then .Compile: System.Xml.Schema.XmlSchemaException: May not be nominated as the {substitution group affiliation} of any...
9
by: ludocluba | last post by:
Hello, here is my problem: I have 3 files: main.c toto.c toto.h: ----------------------------------------------------------- toto.h: #ifndef _toto_h #define _toto_h int var; void test(void);...
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
14
by: Lee Franke | last post by:
I can't seem to figure this one out. Here is my class structure namespace name { public class foo { } }
1
by: prasath03 | last post by:
Hi, I am struggling with the following problem. Can somebody pls help me?. I am developing a wesbite for user can edit their files only, so i am going to develop a page for a Tree Structure in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.