Problem Statement
Our unmanned space vehicle responds to command sequences where each command is
a single uppercase character that describes an action relative to the current
location and orientation of the drone:
- F -- move forward one unit
- Y -- yaw 90 degrees counterclockwise as seen from the top of the drone
- R -- roll 90 degrees counterclockwise as seen from the back of the drone
Definition
- Class:
- SpaceDrone
- Method:
- whereAmI
- Parameters:
- String
- Returns:
- int
- Method signature:
- int whereAmI(String commands)
- (be sure your method is public)
Notes
- Notice that the orientation of the xyz coordinate system is irrelevant since you only need to return the final x coordinate.
Constraints
- commands contains between 1 and 50 characters inclusive
- each character in commands is uppercase F, Y, or R
Examples
"FFF"
Returns: 3
The drone goes forward along the x axis 3 units, ending at (3,0,0)"YYRRYRY""
Returns: 0
The drone has done multiple rotations, but has never moved from (0,0,0)"YFYFY"
Returns: -1
"YFRRYFFFY"
Returns: 3