0

hello! I'm supposed to write a wordguess program that basically runs like the hangman game on iphone, here is my code:

import java.util.Random;
import java.util.Scanner;

public class Wordguess123 {
public static String replaceCharAt(String s, int pos, char c) {
    return s.substring(0,pos) + c + s.substring(pos+1);
 }
 public static void main(String[] args){
        Scanner Jerry = new Scanner(System.in);
        Random Rong = new Random(10);
        String word;
        boolean guess = true;
        int i = 0;
        String win = "YOUWIN!!!!";
        System.out.println("This is Jerry Rong's wordguess game!");
        
        switch (Rong.nextInt()) {
            
            case 1: word = "PROPORTION";
            break;
            case 2: word = "DISTANCE";
            break;
            case 3: word = "MOMENTUM";
            break;
            case 4: word = "HELLO";
            break;
            case 5: word = "GRAPHIC";
            break;
            case 6: word = "ACCELERATION";
            break;
            case 7: word = "ENERGY";
            break;
            case 8: word = "NINJA";
            break;
            case 9: word = "FINALS";
            break;
            default: word = "CHRISTMAS";
            break;
     }
     
     int length = word.length();
     String blank = null;
     for (int h = 0; h < length; h++)
     {  blank = "_" + " ";}
     
     System.out.println(blank);
     String PeoplesGuess = blank;
     
     do {
      i++;
      String letter = in.next();
     letter = letter.toUpperCase();
     if (letter =! "!") {
     
        for (int k = 0; k < length; k++){

                    if (letter.charAt(0) == word.charAt(k)) {
                        current = replaceCharAt(current, k, letter.charAt(0));
                    }
                    
                }
        
        if (current.equals(word)) {System.out.println("You win!!");     } 
        System.out.println ("you used" + i + "guesses ");
        System.out.println ("The secret word is" + word  );
            }
            
     else 
     {
         System.out.println("Guess the word in uppercase.");
         String guessedword = in.next();
         guess = false;
         if (guessedword.equals(word)) {System.out.println(win));}
         else System.out.println("Haha you lose");
         System.out.println ("you used" + i + "guesses ");
        System.out.println ("The secret word is" + word  );
         
         
        }
    
        
        
        
}
while ( i < 27 && guess = true);
5
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by stultuske
0

So....

is there a specific error you want to tell?
are you asking us for suggestions or instructions?
Are you unsure of what to do next?
or maybe the code doesn't give the correct output?

please specify

Edited by zeroliken: n/a

0

when i compile it, it says ; required in line 73 but i dont see any error

0

well ...
either this is not your entire code, or I don't doubt you're getting error messages.
a class should always end with a } to close the class scope, not with

while ( i < 27 && guess = true);
0

Also you appear to have an extra ) here:

if (guessedword.equals(word)) {System.out.println(win)[B][U])[/U][/B];}
0

Also you appear to have an extra ) here:

if (guessedword.equals(word)) {System.out.println(win)[B][U])[/U][/B];}

I had the same problem in JCreator, but this ocde runs fine in Netbeans.
__________________________________________________
Plastic Card Printing

0

I kind of doubt that.
as you said yourself, when you compile, the compiler says:

when i compile it, it says ; required in line 73 but i dont see any error

that extra ) is what the compiler refers to. it expects a ; not a )

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.