Welcome to Dream.In.Code
Become a Java Expert!

Join 150,040 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,596 people online right now. Registration is fast and FREE... Join Now!




Can someone see complie this for me?

 
Reply to this topicStart new topic

Can someone see complie this for me?

thegreatpan12
6 Jun, 2008 - 05:11 PM
Post #1

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 7

Hi, i just worked on this code and for some reason i cant complie it, can someone put it in there java for me and complie it for me and see if it works? If not please tell me! thanks!!!
CODE

import javax.swing.*;
import java.io.*;

public class hang {
public hang() {



String input, guess;
String current_guesses = "";
String guessed_letters = "";
String display_string;
int i, j, cnt, y;
int guesses_left = 10 , matched_letters = 0;
boolean letter_match , full_match, unique_guess;

input = JOptionPane.showInputDialog(null, "insert your word");
if (input == null) return;


cnt= input.length();
if (cnt==0) return;
if (cnt > guesses_left ) {
JOptionPane.showMessageDialog(null,"String too long. Make it shorter than " + guesses_left );
new hang();
return;
}

String hm[] =new String[cnt];
String disp[] =new String[cnt];

//put the word in an array, a letter at a time
for (i=0; i<cnt; i++) {
hm[i] = input.substring(i,i+1);
disp[i] = "_";
System.out.println(disp[i]+" "+hm[i]);
}



for ( --guesses_left; guesses_left >= 0; guesses_left-- ) {

unique_guess = true;
do {
guess = JOptionPane.showInputDialog(null, "Guess a single Letter you have not Guessed before"); // The user guesses a letter only.
if (guess==null) return;
if (guess.length()==1) {
//System.out.println("indexof = " + guessed_letters.indexOf(guess) );
if (guessed_letters.indexOf(guess) < 0 ) unique_guess = true; // -1 means not found
else unique_guess=false;
}
} while (guess.length() != 1 | (!unique_guess) ); // Force the user to only enter 1 letter

if (guessed_letters.length() == 0) guessed_letters = guess;
else guessed_letters = guessed_letters + ", " + guess; // String of guessed characters.

//l=0;
letter_match = false; // assume no match
for ( y=0; y<cnt; y++ ) { // Look for a matching character.

if (hm[y].equalsIgnoreCase(guess)) { // Does the letter match?
letter_match = true;
matched_letters++;
disp[y] = hm[y]; // Set output string to the proper letter & proper case
} // if letter matches
} // for (y=0)


full_match = true;

for (y = 0; y < cnt; y++) { if (!disp[y].equals(hm[y])) full_match = false; }

if ( full_match ) {
JOptionPane.showMessageDialog(null,"Congratulations, you won\nThe correct word was '"+input+"'");
new hang();
return;
}

for (j=0, display_string = ""; j < cnt; j++ ) display_string = display_string + disp[j];

if (letter_match) {
JOptionPane.showMessageDialog(null,"Correct guess ya beast\n"+
display_string + "\n "+guesses_left+" guesses left\nold guesses: "+ guessed_letters);
}

else {
JOptionPane.showMessageDialog(null,"Wrong guess ya beast\n"+
display_string + "\n "+guesses_left+" guesses left\n old guesses: "+guessed_letters);
}

}

JOptionPane.showMessageDialog(null, "All out of guesses, try again");
new hang();

}

public static void main(String[]args) {
new hang();
}
}


This post has been edited by thegreatpan12: 6 Jun, 2008 - 06:54 PM
User is offlineProfile CardPM
+Quote Post

skin_
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 06:42 PM
Post #2

New D.I.C Head
*

Joined: 5 Apr, 2008
Posts: 33

Nope, can't find "new Gam3r();" on line 118
User is offlineProfile CardPM
+Quote Post

thegreatpan12
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 06:54 PM
Post #3

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 7

QUOTE(skin_ @ 6 Jun, 2008 - 07:42 PM) *

Nope, can't find "new Gam3r();" on line 118


can you try again? i just fixed it up a little
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 07:51 PM
Post #4

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE(thegreatpan12 @ 6 Jun, 2008 - 07:54 PM) *

QUOTE(skin_ @ 6 Jun, 2008 - 07:42 PM) *

Nope, can't find "new Gam3r();" on line 118


can you try again? i just fixed it up a little



IMO this will waste all your precious time.. its better if you first fixed the problem on why its not compiling in your computer rather than waiting for someone here to test it..

if it doesn't compile in your pc.. then the chance is it doesn't compile at all.. blink.gif blink.gif


QUOTE


new hang()



thats not the proper way of creating an instance of a class..

hang hangVar = new hang();



This post has been edited by mensahero: 6 Jun, 2008 - 07:53 PM
User is offlineProfile CardPM
+Quote Post

skin_
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 07:51 PM
Post #5

New D.I.C Head
*

Joined: 5 Apr, 2008
Posts: 33

Yep, you're just missing two "}" at the end of the code.
User is offlineProfile CardPM
+Quote Post

thegreatpan12
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 07:55 PM
Post #6

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 7

QUOTE(skin_ @ 6 Jun, 2008 - 08:51 PM) *

Yep, you're just missing two "}" at the end of the code.

thanks man i appreciate it!
User is offlineProfile CardPM
+Quote Post

thegreatpan12
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 08:48 PM
Post #7

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 7

QUOTE(mensahero @ 6 Jun, 2008 - 08:51 PM) *

QUOTE(thegreatpan12 @ 6 Jun, 2008 - 07:54 PM) *

QUOTE(skin_ @ 6 Jun, 2008 - 07:42 PM) *

Nope, can't find "new Gam3r();" on line 118


can you try again? i just fixed it up a little



IMO this will waste all your precious time.. its better if you first fixed the problem on why its not compiling in your computer rather than waiting for someone here to test it..

if it doesn't compile in your pc.. then the chance is it doesn't compile at all.. blink.gif blink.gif


QUOTE


new hang()



thats not the proper way of creating an instance of a class..

hang hangVar = new hang();

ah so i need to replace new hang with hang hangVar = new hang(); ?
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 09:14 PM
Post #8

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions

What I meant was its the proper way of instantiating a class.. If you don't have to change it then don't..

and.. I've been testing your code.. IDK the correct word but I don't think it works.. The first key I press always a correct key.. IDK why.. and I cant find the correct answer to be guessed in your code..
User is offlineProfile CardPM
+Quote Post

thegreatpan12
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 09:33 PM
Post #9

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 7

QUOTE(mensahero @ 6 Jun, 2008 - 10:14 PM) *

What I meant was its the proper way of instantiating a class.. If you don't have to change it then don't..

and.. I've been testing your code.. IDK the correct word but I don't think it works.. The first key I press always a correct key.. IDK why.. and I cant find the correct answer to be guessed in your code..

can you be more specific about the program not working? haha sorry i need to know i need this done by monday and i dont got java at home =[
User is offlineProfile CardPM
+Quote Post

pbl
RE: Can Someone See Complie This For Me?
6 Jun, 2008 - 09:40 PM
Post #10

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Compiles well under my Eclipse
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:49PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month