2
  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);
        }


    }

Here's the homework question:

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.

I'm just trying to fix the user specified time interval (at the moment), and I'm having trouble implementing it.

If I attempt this code

if (myf.isTapped() = true) {
            myf.setWheelVelocities(-255,0,tapBack);
        }

I get an error on:

if (myf.isTapped() = true)

Saying

The left-hand side of an assignment must be a variable

I'm struggling on how to get the robot to move backwards if the myf.isTapped = true

Maybe myf.isTapped cannot take boolean values?

I'm using http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html for user input (integer in this case)

Also, I think the my.isTapped is from an external Jar file.

1
  • 2
    try if (myf.isTapped() == true) or even better: if (myf.isTapped()) Commented Dec 15, 2012 at 17:33

3 Answers 3

3

Change it to

if (myf.isTapped() == true)

or even better

if (myf.isTapped())

= means assignment, == means comparison.

Sign up to request clarification or add additional context in comments.

Comments

2

Try changing

 if (myf.isTapped() = true)

to

 if (myf.isTapped())

2 Comments

'myf.isTapped()' is supposed to be returning 'boolean' then why this extra check. However your not changing anything at all. Correct your answer
Yes. It's great now. +1 ;-}
-1

In all languages (at least in jS, Python, Java, and C#) = means assignment. == is the "equal to" operator.

I come from a Python background so:

test = True
if test == True:
    print("Hello")
else:
    print("Goodbye")

The result from running this code would be

Hello

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.