Menu

Written Public Instance Method Moveby Whose First Argument Int Representing Distance Move Q43831609

I have written a public instance method moveBy() whose firstargument is an int representing the distance to move and whosesecond argument is a char representing the direction in which tomove. It should return no value.

Table 1: Directions and corresponding x and y increments

Direction xInc yInc (this is not a code)Right ‘R’ 1 0Left ‘L’ -1 0Up ‘U’ 0 -1Down ‘D’ 0 1

I need to begin by declaring local int variables xInc and yIncand use the table above to set these for the appropriate incrementsdepending on the supplied argument for direction.

This is what I have done so far: please if someone can correctme and help me! many thanks

public void moveBy(int distance, char direction) {int xInc = 0;int yInc = 0;}

or I tried this for the first bit but it says’ identifierexpected’.

int xInc = 1,-1, 0, 0int yInc = 0, 0, -1, 1

Expert Answer


Answer to I have written a public instance method moveBy() whose first argument is an int representing the distance to move and wh…

OR