I am trying to reset the timer so it can pull another value from my array. Does anyone know the solution? My error is saying:
peat = peat= 1;
local variables referenced from an inner class must be final or effectively final
I am stuck and I know I need to reset the timer but I don't know how.
class MyProgram {
public static void main(String[] args) {
int peat = 0;
int cdown = 0;
Scanner input1 = new Scanner(System.in);
System.out.println("What is your name");
String personsName = input1.next();
System.out.println((personsName) + " Are you ready to impove yourself");
String motiv = input1.next();
String[] myArray = new String[4];
myArray[0] = "Keep going";
myArray[1] = "1 more rep";
myArray[2] = "you have come so far don't stop now";
myArray[3] = "Think of the progress you have made";
if (motiv.equals("yes")) {
System.out.println("Today is the day hard work begins");
} else {
System.out.println("type yes when you're ready to work");
}
Scanner input2 = new Scanner(System.in);
System.out.println("You will recive quotes throughout your workout to remind you to keep working type ok if you accept");
String confirm = input2.next();
if (confirm.equals("ok")) {
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
final Runnable runnable = new Runnable() {
int countdown = 10;
public void run() {
System.out.println(countdown);
countdown--;
if (countdown == 0 && peat < 4) {
System.out.println(myArray[0]);
//reset count down to 10
peat = peat + 1;
} else {
scheduler.shutdown();
}
}
};
scheduler.scheduleAtFixedRate(runnable, 0, 1, TimeUnit.SECONDS);
}
while (cdown < 1) {
System.out.println(myArray[1]);
cdown = cdown + 1;
}
}
}