Question: I have written a public instance method moveBy() whose first argument is an int representing the distance to move and whose second argument is a

I have written a public instance method moveBy() whose first argument is an int representing the distance to move and whose second argument is a char representing the direction in which to move. 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 0 Left 'L' -1 0 Up 'U' 0 -1 Down 'D' 0 1 

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

This is what I have done so far: please if someone can correct me 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' identifier expected'.

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!