[Li Xinyi] iP#98
Open
LI-XINYI1 wants to merge 35 commits into
Open
Conversation
This reverts commit 5cae0c1.
kelvneo
reviewed
Feb 19, 2022
| public TaskManager() { | ||
| } | ||
|
|
||
| public void welcome() { |
There was a problem hiding this comment.
Perhaps change your method name to an action, like printWelcome()
Comment on lines
+8
to
+114
| public static void main(String[] args) throws IOException { | ||
|
|
||
| Scanner in = new Scanner(System.in); | ||
| String command; | ||
| String taskDescrip; | ||
| String[] taskWord; | ||
| TaskManager tManager = new TaskManager(); | ||
| String horiLine = "____________________________________________________________\n"; | ||
|
|
||
| //load record | ||
| try { | ||
| tManager.initialiseNewFile(); | ||
| } catch (FileNotFoundException e) { | ||
| System.out.println("File not found."); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| tManager.welcome(); //greating | ||
|
|
||
| command = in.nextLine(); | ||
| while (!command.equals("bye")) { | ||
|
|
||
| String[] word_split; | ||
| word_split = command.split(" ", 2); | ||
| String taskName = word_split[0]; | ||
|
|
||
| //different functions based on command lines | ||
| switch (taskName) { | ||
| case "todo": | ||
| tManager.addTask(new Todo(word_split[1])); | ||
| break; | ||
| case "deadline": | ||
| try { | ||
| taskWord = word_split[1].split("/by ", 2); | ||
| taskDescrip = taskWord[0]; | ||
| String ddl = taskWord[1]; | ||
| tManager.addTask(new Deadline(taskDescrip, ddl)); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); | ||
| } catch (BaymaxException b){ | ||
| System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); | ||
| } | ||
| break; | ||
| case "event": | ||
| try { | ||
| taskWord = word_split[1].split("/at ", 2); | ||
| taskDescrip = taskWord[0]; | ||
| String eventTime = taskWord[1]; | ||
| tManager.addTask(new Event(taskDescrip, eventTime)); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); | ||
| } catch (BaymaxException b){ | ||
| System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); | ||
| } | ||
| break; | ||
| case "list": | ||
| tManager.printTaskList(); | ||
| break; | ||
| case "mark": | ||
| System.out.println(horiLine); | ||
| try { | ||
| tManager.markTask(Integer.parseInt(word_split[1]) - 1); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("Please input an integer for task index."); | ||
| } catch (BaymaxException b){ | ||
| System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); | ||
| } | ||
| System.out.println(horiLine); | ||
| break; | ||
| case "unmark": | ||
| System.out.println(horiLine); | ||
| try { | ||
| tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("Please input an integer for task index."); | ||
| } catch (BaymaxException b){ | ||
| System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); | ||
| } | ||
| System.out.println(horiLine); | ||
| break; | ||
| case "delete": | ||
| System.out.println(horiLine); | ||
| try { | ||
| tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("Please input an integer for task index."); | ||
| } catch (BaymaxException b){ | ||
| System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); | ||
| } | ||
| //check branch merge | ||
| System.out.println(horiLine); | ||
| break; | ||
| default: | ||
| System.out.println(horiLine); | ||
| System.out.println("Error. Please retry"); | ||
| System.out.println(horiLine); | ||
| break; | ||
| } | ||
| command = in.nextLine(); | ||
|
|
||
| } | ||
| tManager.saveTask(); | ||
| tManager.bye(); //bye | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Try to SLAP your method here as it is too long
Comment on lines
+78
to
+88
| if(!dir.exists()){ | ||
| dir.mkdir(); | ||
| System.out.println("create a new directory \"data\"...... "); | ||
| } | ||
| File file = new File("data/Baymax.txt"); | ||
| if(!file.exists()) { | ||
| file.createNewFile(); | ||
| System.out.println("create a new file \"Baymax.txt\"...... "); | ||
| System.out.println(horiLine); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Be sure to add spaces after your if statements (i.e. if (!dir.exists()) {)
|
|
||
| public void saveTask() throws IOException { | ||
|
|
||
| FileWriter fw = new FileWriter("data/Baymax.txt"); |
There was a problem hiding this comment.
Magic literal here, try to declare it as a static constant above.
Comment on lines
+69
to
+75
| try { | ||
| tManager.markTask(Integer.parseInt(word_split[1]) - 1); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("Please input an integer for task index."); | ||
| } catch (BaymaxException b){ | ||
| System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); | ||
| } |
There was a problem hiding this comment.
I believe this would cause an error if you type in any non-numeric input for your second option. mark abc would throw a NumberFormatException if not handled correctly.
Level 9: find: find a task by searching for a keyword
Level-8: dates and times
A-JavaDoc: Add JavaDoc comments to the code.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.