Lab Assignment 04 – To Do List v2 solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

Problem Description • In this assignment you will add functionality to the To-Do-List from Assignment 3 so that: o The Program will save to, and load records from a text file o Comparators can be used to Sort Tasks by title, priority, and isComplete o The comparators will be made available to you; you need to use them for sorting. o The JUnit test file has been updated with more tests for class Task Program Design (Updated) (Diagram created using UMLet)
Implementation Notes Class Task • Add an overloaded constructor that has 3 parameters, one per field • Update the validation for Title to throw ValidationException if the user enters a tab character as part of a Title, e.g. “There are tabs here” (Priorities must be “high”, “medium” or “low”, this already prevents tab characters) • Add a method named createTabRecord() that returns a String with the Title, Priority, and IsComplete separated by Tab Characters. Tip: Don’t forget about \t (We will be saving Tasks as text-based records, using tabs to separate fields) Tip: The String class has a method named contains(), that you can pass “\t” into to check for tabs.
Class ValidationException / Class ToDoListLauncher • No changes needed to these files from Assignment 3 Class ToDoListManager • Updates Needed: o Update the class constants adding the new ones as per the UML above o Update the runToDoList and showMenu methods to align with the updated constants o Add methods as seen in the UML for the new program features: saveTasks(), loadTasks(), sortByTitle, sortByPriority(), sortByIsComplete() • When saving o If there are no tasks in the ArrayList tell the user there is nothing to save o If there are tasks, save them into a file named “Tasks.txt” replacing the older file if it exists Loop over the ArrayList and write one line per Task into the file o Tip: write lines to the file, each one with the values for title, priority, isComplete as Strings separated by tabs (but no spaces between values) See method createTabRecord above • When loading o Clear the ArrayList of any Tasks o Read the records in from the text file (tip: loop) o Split each line into a String array, splitting on the tab character o Create a new Task using the data spit from the line o Add the new Task to the ArrayList • When sorting o If there are no tasks tell the user there is nothing to sort o Use Collections.sort on the ArrayList with the appropriate Comparator in each method Tip: • This program still uses one Scanner(System.in) with a mix of calls to nextInt() and nextLine(), make sure you call nextLine() after every nextInt() to remove leftover line-terminator characters from the input Stream (System.in). • Also, if an InputMismatchException is thrown and caught make sure your nextLine() on the Scanner to clean out bad data. Assignment Tasks • An Updated Unit test file is provided, it tests class Task for: validation for no Tab characters, the createTabRecordMethod(), the new constructor • Use the UML class diagram, comparator code, and implementation notes to update the program. • Find one web tutorial on file-IO in Java and cite with APA style. • Find one web tutorial on interfaces and interface based polymorphism in Java and cite with APA style. • Comment all parts of the program, old code, new code, with Javadoc comments. o NOTE: You are not required to write comments for the Unit Tests, or the Comparator classes • Generate Javadoc docs for the project, with private members documented also • Write one-page essay, using MS Word, that addresses the discussion questions (below) as a guide to discuss what was accomplished in the assignment, cite and reference any sources used online to help you answer questions. (You may use more than one page, but professors will stop reading after 3 pages).
Discussion Questions (Cite and reference any sources you use) • What happens if you do not write source code to close an open file in a computer program? o What is a resource leak? o Why are resource leaks bad? • Did you use try-catch-finally with file.close() or try-with-resources? o What are some advantages and drawbacks of either approach? • Is Collections.sort(List