我正在参加香港科技大学edX的课程。在一项任务中,我制作了一个程序来播放Rock,Paper,Scissors。 在那里,当我去比较选择时,我得到一个编译错误'int不能被解除引用'
import comp102x.ColorImage;
import comp102x.IO;
import comp102x.Canvas;
/**
* The Choice class represents a choice made by the player or the computer.
* It can be either "rock", "paper", or "scissors".
*/
public class Choice
{
private int type; //stores the choice type: 0=rock, 1=paper, 2=scissors
/**
* The constructor
*
* @param type the choice type to be represented by this Choice object
*/
public Choice(int type)
{
//initialize the "type" instance varialble
this.type = type;
}
/**
* Get a number that represents the choice type
*
* @return a number that represents the choice type: 0=rock, 1=paper, 2=scissors
*/
public int getType()
{
return type;
}
/**
* Compare "this" with anotherChoice
*
* @param anotherChoice the choice to be compared
* @return either 1, -1, or 0 which indicates the comparison result: 1 means "this" wins anotherChoice; -1 means "this" loses to anotherChoice; 0 means "this" and anotherChoice are the same
*/
public int compareWith(Choice anotherChoice)
{
// write your code after this line
IO.output("Please input your choice (0=rock, 1=paper, 2=scissors)");
type = IO.inputInteger( );
anotherChoice = new Choice(0);
int gameResult = type.compareWith(anotherChoice);
switch(gameResult)
{
case -1: IO.outputln("You Win!"); break;
case 0: IO.outputln("Draw!"); break;
case 1: IO.outputln("You Lose!"); break;
}
return gameResult; // this line should be modified/removed upon finishing the implementation of this method
}
请帮助!!