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