i still having this errors also if i've imported java.util.Arrays
:
Hangman.java:43: error: cannot find symbol
char[] randomWordToGuess = randomWordToGuessC.toCharArray() ;
^
symbol: variable randomWordToGuessC
location: class Hangman
Hangman.java:94: error: cannot find symbol
for (int i = 0; i < array.length; i++ ) {
^
symbol: variable array
location: class Hangman
Hangman.java:95: error: cannot find symbol
System.out.println(array[i] + "");
^
symbol: variable array
location: class Hangman
Hangman.java:100: error: cannot find symbol
for (int i = 0; i < array.length; i++ ) {
^
symbol: variable array
location: class Hangman
Hangman.java:101: error: cannot find symbol
if (array[i] == '_') return false;
^
symbol: variable array
location: class Hangman
5 errors
my code is:
import java.util.Random ;
import java.util.Scanner ;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import java.util.Arrays;
public class Hangman {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
Random random = new Random();
String ciao = "ciao";
String programmazione = "programmazione";
String frutto = "frutto";
String cianbella = "cianbella";
String[] guesses= {"ciao", "ciambella","frutto"};
//char[] guessesChar = guesses.toCharArray() ;
// String randomGuesses= (guesses.[random().nextInt(guesses.length)]);
boolean weArePlaying = true;
while (weArePlaying) {
System.out.println("Benvenuto all' impiccato di MatStar15");
for (int i = 1; i <= 1; i++) {
//* INIZIO RANDOM
ArrayList<String> companyName = new ArrayList<String>();
companyName.add("Ciao");
companyName.add("frutta");
companyName.add("Twitter");
companyName.add("Paypal");
companyName.add("Uber");
companyName.add("Yahoo");
//Get Random Company Name from Arraylist using Random().nextInt();
String randomWordToGuessC = companyName.get(new Random().nextInt(companyName.size()));
}
// * FINE RANDOM
char[] randomWordToGuess = randomWordToGuessC.toCharArray() ;
// char randomWordToGuess = guesses[random.nextInt(guesses.length)].toCharArray();
int amountOfGuesses = randomWordToGuess.length; //100
char[] playerGuess = new char[amountOfGuesses];//_ _ _ _ _
for (int i = 0; i < playerGuess.length; i++ ) {
playerGuess[i] = '_' ;
}
boolean wordIsGuessed = false;
int tries = 0;
while (!wordIsGuessed && tries != amountOfGuesses) {
System.out.println("numero di tentativi: \n");
printArray(playerGuess);
System.out.printf("hai altri ");
System.out.printf("tries ", amountOfGuesses - tries + "\n");
System.out.printf ( " tentativi.\n") ;
System.out.println("digita un solo carattere");
char input = scanner.nextLine().charAt (0); //shadgsv --> solo "s"
tries++;
if (input=='_') {
weArePlaying = false ;
wordIsGuessed = true ;
} else {
for (int i = 0; i < randomWordToGuess.length; i++ ) {
if (randomWordToGuess[i] == input) {
playerGuess[i] = input;
}
}
if (isTheWordGuessed(playerGuess)) {
wordIsGuessed = true ;
System.out.println ("congratuliazioni hai vinto!");
}
}
}
if (!wordIsGuessed) System.out.println("hai finito i tentativi :/");
System.out.println("vuoi fare un'altra partita? (si/no)");
String anotherGame = scanner.nextLine ();
if (anotherGame.equals("no")) weArePlaying = false;
}
System.out.println("GameOver");
}
public static void printArray(char[] Array) {
for (int i = 0; i < array.length; i++ ) {
System.out.println(array[i] + "");
}
System.out.println() ;
}
public static boolean isTheWordGuessed(char[] Array) {
for (int i = 0; i < array.length; i++ ) {
if (array[i] == '_') return false;
}
return true;
}
}
what can i do for fixing everything and maybe also compact everything ?
Aucun commentaire:
Enregistrer un commentaire