【发布时间】:2016-11-06 13:34:38
【问题描述】:
将我的 Game 类中的方法调用为我的刽子手游戏的主要方法时遇到困难。 我们应该旋转一个轮子来获得 100,250 或 500 美元的头奖金额,然后按照您的期望玩游戏……但是方法是必要的。我还差得很远,我只想在这一点上调用我的方法,看看它是如何工作的。 这是我的代码:
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: 错误:找不到符号 System.out.print("之后 旋转轮子,你得到 " + spinWheel()); ^
【问题讨论】:
-
你的问题是......?
-
对不起。当我调用 spinWheel 方法时,我的主要方法中有错误。不知道我做错了什么
-
那些错误是......?
-
GameDemo.java:11: 错误: 找不到符号 System.out.print("旋转轮子后,你得到了" + spinWheel()); ^
-
“符号”指向 spinWheel