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
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