CS 141: Introduction To Programming: Dr. Susan Bergin
CS 141: Introduction To Programming: Dr. Susan Bergin
Lecture 19
Robots Revisited
But how do you get the program to continually check the selection statment?
{!
Putting It Together
public class TouchRobotLoop1{!
! public static void main(String[] args) {!
! !
RoboCar robot = new RoboCar();!
! !
robot.setMotorSpeed(360);!
! !
while(true)!
! !
{!
! !
!
if ( robot.touchSensorIsPressed() )!
! !
!
{!
! !
!
!
robot.moveBackward(1000);!
! !
!
}!
! !
!
else!
! !
!
{!
! !
!
!
robot.moveForward(1000);!
! !
!
}!
! !
}!
! }!
}!
More methods
moveForwardForDistance(float distance)
moveBackwardForDistance(float distance