我有一个任务来制作井字游戏的consol游戏,但我有点卡住了。教师提供了编码和驱动程序类的测试标准来测试我的TicTacToe.java。如果我在PlayTicTacToe.java的驱动程序类中运行以下,那么所有的工作都很好。Java驱动程序类错误
TicTacToe ttt = new TicTacToe();
ttt.playGame();
但是,如果我使用教师提供的(下),我得到的错误,我不知道为什么。
Scanner s = new Scanner(System.in);
TicTacToe tictactoe = new TicTacToe('Sally', 'John');
System.out.print(“Would you like to play a game? Y/N: ”);
String play = s.nextLine();
while(play.equals('Y'))
{
tictactoe.playGame();
System.out.print(“Would you like to play a game? Y/N: ”);
play = s.nextLine();
}
TicTacToe tictactoe1 = new TicTacToe(“Sally”, “John”);
TicTacToe tictactoe2 = new TicTacToe(“Sally”, “John”);
// this will show true
System.out.println(tictactoe1.equals(tictactoe2));
// this will invoke the toString as shown above
System.out.println(tictactoe1);
我得到的错误是上线井字游戏井字游戏=新井字游戏(“莎莉”,“约翰”);它会在'Sally'上产生一个红色下划线'错误的常量章程'错误
任何建议?
单个字符用单引号''y''表示。字符串使用双引号'“John”'。所以用双引号替换单引号。 – 2012-02-11 23:06:08