Yesterday I asked this question regarding a while loop not ending and was told I need to set "correct" to true inside my main method using a setter. I did some research on setters and getters and I am completely lost. What exactly do they do and how do I use one in this situation?
EDIT: Thank you Ben Wainwright for your answer!
Main Method:
while (lives > 0 && correct == false) {
startTime = System.currentTimeMillis();
timeObject.time2();
levelinfoObject.levelInfo(currentlevel);
timeObject.time1();
levelinfoObject.livesInfo(lives);
timeObject.time1();
levelinfoObject.skipsInfo(skips);
timeObject.time2();
questionsObject.questionOne(lives, correct, choice, skips, currentlevel)
}
Questions one method in the questions class:
public void questionOne(int lives, boolean correct, String choice, int skips, int currentlevel) {
Scanner scanner = new Scanner(System.in);
System.out.println(" ");
System.out.println("Question: If there are 6 apples in a tree and you take 4, how many do you have?");
timeObject.time2();
System.out.println("A: 3");
System.out.println("B: 4");
System.out.println("C: 2");
System.out.println("D: 6");
while (correct == false && lives > 0) {
choice = scanner.nextLine();
switch(choice) {
case "a":
System.out.println("WRONG! Try again.");
lives = lives - 1;
break;
case "b":
System.out.println("CORRECT! You have the 4 you took obviously.");
correct = true;
break;
case "c":
System.out.println("WRONG! Try again.");
lives = lives - 1;
break;
case "d":
System.out.println("WRONG! Try again.");
lives = lives - 1;
break;
case "skip":
if (skips > 0) {
System.out.println("You have skipped level " + currentlevel + "!");
skips = skips - 1;
correct = true;
}
else {
System.err.println("You do not have any skips left!");
}
break;
default:
System.err.println("Please type an answer.");
break;
}
}