Hello im new in java , i have developed a code but i think it contains too many errors.
I have to design a java game based on guessing a word.
The game has 3 guesses which are randomly choosen, and every one of those has a current answer.
for example:
"shines and is yellow and roundround "
(secret answer: sun)
"Its cold and light"
(secret answer: snow)
"It has strings and a woman shape"
(secret answer: guitar)
Once one of the three keys is choosen randomly the user has 3 chances to be able to guess the right word, after the 3rd time the game has to display "you have lost"
If you guess the right word within the 3 chances give there has to be displayed the phrase,
"congratulations you have won"
here is the code:
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;
class guess {
public static void main(String[] args) {
String arr_keys[] = { // guesses
"shines and is yellow and looks round",
"Its cold and light"
"It has strings and a woman shape",
};
String arr_ans[] = { // answers
"sun",
"snow",
"guitarl"
};
int numIntentos = 0;
Scanner miScanner = new Scanner(System.in);
int numRandom = new Random(). nextInt(3) ;
//System.out.println("Random: " + numRandom);
System.out. println ("********************************************" );
System.out. println ("welcome \"This is guess the word game!!\"");
System.out. println ("********************************************" );
System.out. println ();
System.out. println ("guess the following...");
System.out. println (arr_keys[numRandom]);
System.out. println ("********************************************" );
System.out. println ("type your answer: ");
String sTexto = miScanner.next();
numIntentos++;
if (sTexto.equals(arr_ans[numRandom])) {
System.out. println ("you have won ");
}
else {
System.out. println ("try again ");
}
}