Question
Complete the following method as described in java. /** * This method builds an int array with 2 cells, representing a movement vector, * based
Complete the following method as described in java.
/** * This method builds an int array with 2 cells, representing a movement vector, * based on the String parameter. * * The rules to create the length 2 int array are as follows: - The 1st * character of the String represents the direction. - The remaining characters * (if there are any) are interpreted as integer and represent the magnitude or * the number of steps to take. * * The cell at index 0 represents movement in the rows. Hence, a negative value * represents moving up the rows and a positive value represents moving down the * rows. * * The cell at index 1 represents movement in the columns. Hence, a negative * value represents moving left in the columns and a positive value represents * moving right in the columns. * * If the first character of moveStr does not match on of MyLevels.UP_CHAR, * MyLevels.DOWN_CHAR, MyLevels.LEFT_CHAR, or MyLevels.RIGHT_CHAR, then return an * array with 0 in both cells. * * If there are no characters after the first character of moveStr or the * characters cannot be interpreted as an int, set the magnitude of the movement * to 1. * * Hint: Use Scanner to parse the magnitude. * * Some examples: - If the parameter moveStr is "81": An array {-1, 0} would * represent moving up by one character. - If the parameter moveStr is "65": An * array {0, 5} would represent moving right by 5 characters. * * @param moveStr The string to parse. * @return The calculated movement vector as a 2 cell int array. */
public static int[] calcDelta(String moveStr) { // FIX ME return null; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started