Convert User Input to an Array of KivaCommands The  RemoteControl class currently takes in a String of commands from the  user that looks like “FFFTRF”.

 Convert User Input to an Array of KivaCommands

The  RemoteControl class currently takes in a String of commands from the  user that looks like “FFFTRF”. However, our Kiva robots cannot  understand instructions in that form. They can simply make one move at a  time, accepting a single KivaCommand. So, we’ll need to take the user  inputted commands and convert them into a more Kiva friendly format, a  list of KivaCommands that we can send to the robot’s move method one at a  time. 

Write the Convert Method Using continue and/or break

Create  a helper method in the RemoteControl class called  convertToKivaCommands(). This method should take a String as a  parameter, which will be the commands that the user types into the  console (for example “FFFTRF”). It should return an array of  KivaCommands (in this case FORWARD, FORWARD, FORWARD, TAKE, TURN_RIGHT,  FORWARD). We recommend doing this by using the values() method of the  KivaCommand enum to get an array of all of the KivaCommands. You can  then use the getDirectionKey() method to determine which KivaCommand  each char in the String should be converted to. If the user enters a  character that does not correspond to a command throw an  IllegalArgumentException with a useful error message.

Note: When  you want to print out the contents of a KivaCommand[] array variable  called commands, for example, you would call Arrays.toString(commands)  to turn the array into a single String. You’ll need to import  java.util.Arrays to use this method. Here is some sample code that you  can play with in BlueJ to demonstrate this, then use the approach for  your needs:

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

Hello Students, As discussed in class, the Workspaces and Challenges are now active. Required Challenges for Full Credit To earn full credit (30% of the

Hello Students, As discussed in class, the Workspaces and Challenges are now active. Required Challenges for Full Credit To earn full credit (30% of the assignment), you must complete 8 challenges from the following list: Interns & HR on the Domain Controller Help Desk Fun: User Workstation Nightmares Dangerous Drives Preventative Protection: Thwarting the Imminent Threat Security

Please read the instructions below carefully. Required Challenges for Full Credit Vulnerability Scan Complete, Begin System Hardening [NG] Volatile

Please read the instructions below carefully. Required Challenges for Full Credit Vulnerability Scan Complete, Begin System Hardening [NG] Volatile Vulnerabilities [NG] The Network is Down! Internal Issues Edition [NG] The Network is Down! Contractor Edition [NG] (Complexity 1) The Network is Down! Contractor Edition [NG] Systems Security Analyst Crash Course

Hello Students, Please pay attention to the instructions below. Required Challenges for Full Credit To earn full credit (30% of the assignment), you must

Hello Students, Please pay attention to the instructions below. Required Challenges for Full Credit To earn full credit (30% of the assignment), you must complete 6 challenges from the following list: Interns & HR on the Domain Controller Help Desk Fun: User Workstation Nightmares Dangerous Drives Preventative Protection: Thwarting the Imminent Threat Security