473,809 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 17 '05 #1
1 2257

"banjo123" <ba************ *@mail.codecomm ents.com> wrote in message
news:1103139200 .f237ce927b5338 871b71d1787cfd9 5ff@tng...

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.jav a"
************** 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 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 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 WacKY
CrAZy GAme!");
JOptionPane.sho wMessageDialog( null, "... or not, try to guess my
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 or
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 first
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 right
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 of
guesses
}else
{
JOptionPane.sho wMessageDialog( 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
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 right
or they run out of guesses
while(!yourLast NameGuess.equal s(myLastName) && lastNameGuesses >
0)
{
JOptionPane.sho wMessageDialog( null, "How could you forget my
last name!");
yourFirstNameGu ess = userGuess("Try again, what's my last
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 names
right
if (lastNameGuesse s > 0 && firstNameGuesse s > 0)
{
JOptionPane.sho wMessageDialog( 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 (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
------------------------------------------------------------------------

---
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
5400
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 source code files are generated using the XJC, it is possible to compile the generated source code using javac generated\*.java generated\impl\*.java , but this only gives me 97 errors.?
3
1970
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 program. The variables involved in the segmentation fault are surrounded by compiler directives. I am 100% sure that I do not have to extern "C"
6
5890
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 http://www.almaden.ibm.com/software/quest/Resources/datasets/syndata.html#assocSynData I tried it on a unix machine and received the following error message: zivunix:compile> make
2
1268
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 hierarchy for a hobby project, and I need to repeat it with several value types. So, I chose to express it with templates. Here is sample code that demonstrates the problem:
5
3340
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 rightType;
2
9094
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 other declaration. An error occurred at , (11, 3). Schema compile error: System.Exception: Schema error ---> System.Xml.Schema.XmlSchemaException: May no
9
3484
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); #endif -----------------------------------------------------------
15
2436
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, the compilation seems to work properly almost all of the time. More on this later. If I launch one copy of the IDE, then I can usually compile the project at least once. At some point, the build fails reporting "Could not copy temporary files...
14
1991
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
2087
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 jsp. I got one java code from internet, that working perfectly in java, it doesn't work after i converted in jsp. I don't know what is the problem in that code. If anybody knows the answer let me know.... When i run that code from jsp it throws the...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.