Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java-programming. How can I make the code below update the coordinates for pos[X

ID: 3727722 • Letter: J

Question

Java-programming. How can I make the code below update the coordinates for pos[X] and pos[Y] everytime i type in a number?

I would like it to work, so if the beginning coordinates are (0,0) and I enter 6, the variable pos will become pos=[1,0], or by entering 2 it becomes [0,1], I have put a picture of the window output I want to achieve, where there's been pressed 6, 2, 6, 9.

public class RaceTrack t final static int x = 0; final static int Y = 1; static List IineCoordinates = new ArrayList; // List with a.! the ines between dots static int moves; // Counter for the number of moves used to finish the course static int pos = new int[2]; // The current position static int oldPos = new int[2]; // The previous position static int[] distance = new int[2]; // Vector between old position and new position static boolean middleCrossed; static boolean clockwise; static boolean sideCrossed; static boolean goal;

Explanation / Answer

You can make a function that takes two variables pos[x] and pos[y] as parameters to the function and updates pos[x] and pos [y] everytime it is called.

Call this function whenever you press or type any number. The function will look something like:-

public void updatePos(int a, int b){

if(a==1){

a=0;

}else{

a=1;

}

if(b==1){

b=0;

}else{

b=1;

}

}

You can call this function on typing number like this:-

updatePos(pos[X], pos[Y]);

Hope this will help!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote