myf = new Finch();
do
{
//menu 4
if (s.equals("Tap Test")) RunTapTest(s);
}
private static void RunTapTest(String s)
{
@SuppressWarnings("resource")
Scanner reader = new Scanner(System.in);
System.out.println("Enter the time interval in which you want the Finch to move backwards: ");
//get user input for tapBack
int tapBack = reader.nextInt();
System.out.println("\n"+"Running: "+s+"\n");
long before = System.currentTimeMillis();
while(System.currentTimeMillis() - before < testtime)
{
System.out.println(myf.isTapped());
//myf.setWheelVelocities(-255,0,testtime);
}
//I can't set myf.isTapped = true
if (myf.isTapped()) {
myf.setWheelVelocities(-255,0,tapBack);
}
}
这是家庭作业问题:
Menu option 4 will determine if the Finch has been tapped on its tail. If so, the Finch should respond with the spoken words “Thanks” and move backwards for a user specified time interval.
我只是想修复用户指定的时间间隔(目前),但在实现它时遇到了麻烦。
如果我尝试这段代码
if (myf.isTapped() = true) {
myf.setWheelVelocities(-255,0,tapBack);
}
我收到错误:
if (myf.isTapped() = true)
说
The left-hand side of an assignment must be a variable
如果 myf.isTapped = true ,我正在努力如何让机器人向后移动
也许 myf.isTapped 不能采用 boolean 值?
我正在使用http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html用于用户输入(在本例中为整数)
另外,我认为 my.isTapped 来自外部 Jar 文件。
最佳答案
关于Java用户输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13894474/