Here I have the code to receive input to the speed. However I am wanting to make it so when type "more" it will give 5 MPH and the next time I type move it will be 10 MPH, so adding 5 to the previous output.
public static void readInputSpeed(String prompt) {
System.out.print(prompt);
String inputSpeed = new Scanner(System.in).nextLine();
Car.speed(inputSpeed);
}
What I am looking for is
User types "more" Output: 5 User types "more" Output: moves from 5 to 10 (so the code stores the previous value and then add 5 to the previous value that it was from the last iteration)
I have tried to insert the block of code into a while loop and that works to get multiple inputs. As for input I am trying to implement, I have tried to use the while loop with a fori loop. I have also tried to use arrays to try to maybe store the input into the array and reference back to that same spot in the array.
Here is the code for the array and loops I used:
public static void readInputSpeed(String prompt) {
String input = "";
int[] array = new int[1];
array[0] = 0;
while (input != "quit") {
System.out.print(prompt);
input = new Scanner(System.in).nextLine();
for (int i = 0; i < 1; i++) {
array[i] = i;
if (input == "more")
i += 5;
else if (input == "less")
i -= 5;
System.out.println(i + " MPH");
}
}
}