難以將我的Game類中的方法調用到我的Hangman遊戲的主要方法中。 我們應該旋轉輪盤才能獲得100,250或500美元的大獎,然後按照您的預期玩遊戲......但方法是必需的。我什麼都沒有接近完成我只是想在這一點上能夠調用我的方法來看看它的工作方式。 這裏是我的代碼:設置我的Hangman方法並在我的主要方法中調用它們
import java.util.Scanner;
import java.util.Random;
public class GameDemo {
public static void main(String[] args) {
String[] songs = {"asdnj", "satisfaction", "mr jones",
"uptown funk"}; //note this is a very short list as an example
Random rand = new Random();
int i = rand.nextInt(songs.length);
String secretword = songs[i];
System.out.print("Welcome to The Guessing Game. The topic is song titles. \nYou have 6 guesses. Your puzzle has the following letters: ");
System.out.print("After spinning the wheel, you got " + spinWheel());
//continue the code here.
}
}
class Game {
Random rand = new Random();
String[] songs = {"asdnj", "satisfaction", "mr jones",
"uptown funk"};
int i = rand.nextInt(songs.length);
private String secretword = songs[i];
private char [] charSongs = secretword.toCharArray();
private char [] guessed = new char [charSongs.length];
private int guesses;
private int misses;
private char letter;
private char [] jackpotAmount = {100,250,500};
public Game(){}
public int spinWheel(int[] jackpotAmount){
int rand = new Random().nextInt(jackpotAmount.length);
return jackpotAmount[rand];
}
public char guessLetter(char charSongs [], char letter){
int timesFound = 0;
for (int i = 0; i < charSongs.length; i++){
if (charSongs[i] == letter){
timesFound++;
guessed[i] = letter;
}
}
return letter;
}
}
而返回錯誤是
GameDemo.java:11: error: cannot find symbol System.out.print("After spinning the wheel, you got " + spinWheel()); ^
,你的問題是......? –
對不起。當我調用spinWheel方法時,我的主要方法中有錯誤。不知道我做錯了 – Pizaz
和那些錯誤是...? –