Last active
April 25, 2016 16:25
-
-
Save lucasmelin/57f641e7f1f0c69570f018b56b876bd4 to your computer and use it in GitHub Desktop.
Toggles task completion by inverting the boolean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Toggles task completion boolean. | |
* <p> | |
* Checks that there are tasks. | |
* Asks user for index of Task in the ArrayList to toggle. | |
* After obtaining the Task from the ArrayList flip the isCompleted boolean. | |
*/ | |
private void toggleTaskComplete(){ | |
if (tasks.isEmpty()==false){ // Make sure there are tasks | |
System.out.println("What is the index of the task you'd like to toggle?"); | |
try{ | |
int userIndex = keyboard.nextInt(); // Get index of task | |
Task currentTask = tasks.get(userIndex); // Get the task | |
currentTask.setIsComplete(!currentTask.getIsComplete()); // Invert the boolean | |
}catch (InputMismatchException e){ | |
System.err.println(e.getMessage()); | |
} | |
catch(IndexOutOfBoundsException e){ | |
System.err.println(e.getMessage()); | |
} | |
} | |
else{ | |
System.out.print("Nothing to toggle, no tasks"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment