diff --git a/src/main/java/Operations/Parser.java b/src/main/java/Operations/Parser.java index 57479ccf7a..49c2e85692 100644 --- a/src/main/java/Operations/Parser.java +++ b/src/main/java/Operations/Parser.java @@ -47,7 +47,7 @@ public String getCommandLine() { * @return index Index the user wishes to perform operations on. */ public Integer getIndex() { - String temp = scanner.nextLine().trim(); + String temp = scanner.next().trim(); int index = Integer.parseInt(temp) - 1; return index; } @@ -115,7 +115,7 @@ public int getAmount(){ * @return the unit of time the customer request to snooze */ public TimeUnit getTimeUnit(){ - String temp = scanner.next(); + String temp = scanner.next().trim(); return TimeUnit.valueOf(temp); } diff --git a/src/main/java/Operations/Storage.java b/src/main/java/Operations/Storage.java index e22c660a80..64101c1ed9 100644 --- a/src/main/java/Operations/Storage.java +++ b/src/main/java/Operations/Storage.java @@ -89,8 +89,10 @@ public ArrayList loadFile(String fileName) throws RoomShareException { String scanUnit = temp[9].trim(); TimeUnit unit = TimeUnit.valueOf(scanUnit); - - String scanSubTask = temp[10].trim(); + String scanSubTask = ""; + if (temp.length > 10) { + scanSubTask = temp[10].trim(); + } if (type.equals(SaveType.A)) { // Assignment type @@ -99,7 +101,7 @@ public ArrayList loadFile(String fileName) throws RoomShareException { assignment.setAssignee(user); assignment.setRecurrenceSchedule(recurrence); assignment.setDone(done); - if (scanSubTask.length() != 0) assignment.setSubTasks(scanSubTask); + if (!scanSubTask.equals("")) assignment.setSubTasks(scanSubTask); taskArrayList.add(assignment); } else { //Meeting type @@ -120,7 +122,7 @@ public ArrayList loadFile(String fileName) throws RoomShareException { } } } - } catch (IOException | ArrayIndexOutOfBoundsException e) { + } catch (IOException | IndexOutOfBoundsException e) { throw new RoomShareException(ExceptionType.wrongFormat); } return (taskArrayList); diff --git a/src/main/java/Operations/TaskCreator.java b/src/main/java/Operations/TaskCreator.java index aca6bd61bf..9893a41002 100644 --- a/src/main/java/Operations/TaskCreator.java +++ b/src/main/java/Operations/TaskCreator.java @@ -121,37 +121,25 @@ public Task create(String input) throws RoomShareException { } else if (type.contains("meeting")) { if (unit.equals(TimeUnit.unDefined)) { // duration was not specified or not correctly input - if( !CheckAnomaly.checkTime(date) ) { - Meeting meeting = new Meeting(description,date); - meeting.setPriority(priority); - meeting.setAssignee(assignee); - meeting.setRecurrenceSchedule(recurrence); - return meeting; - } - else - throw new RoomShareException(ExceptionType.timeClash); + Meeting meeting = new Meeting(description,date); + meeting.setPriority(priority); + meeting.setAssignee(assignee); + meeting.setRecurrenceSchedule(recurrence); + return meeting; } else { - if( !CheckAnomaly.checkTime(date, duration, unit) ) { - Meeting meeting = new Meeting(description, date, duration, unit); - meeting.setPriority(priority); - meeting.setAssignee(assignee); - meeting.setRecurrenceSchedule(recurrence); - return meeting; - } - else - throw new RoomShareException(ExceptionType.timeClash); + Meeting meeting = new Meeting(description, date, duration, unit); + meeting.setPriority(priority); + meeting.setAssignee(assignee); + meeting.setRecurrenceSchedule(recurrence); + return meeting; } - } - - if (type.contains("leave")) { + } else if (type.contains("leave")) { //short leave Leave leave = new Leave(description, assignee, date, duration, unit); leave.setPriority(priority); leave.setRecurrenceSchedule(recurrence); - } - - return null; + return leave; } else throw new RoomShareException(ExceptionType.wrongTaskType); } } \ No newline at end of file diff --git a/src/main/java/Operations/TaskList.java b/src/main/java/Operations/TaskList.java index ee3bf89f68..0583d815c6 100644 --- a/src/main/java/Operations/TaskList.java +++ b/src/main/java/Operations/TaskList.java @@ -207,4 +207,16 @@ public void snooze (int index, int amount, TimeUnit timeUnit){ break; } } + + public int getSize() { + return tasks.size(); + } + + public int getDoneSize(){ + int count = 0; + for (Task t: tasks){ + if (t.getDone()) count++; + } + return count; + } } diff --git a/src/main/java/Operations/Ui.java b/src/main/java/Operations/Ui.java index 8919650441..8965c51794 100644 --- a/src/main/java/Operations/Ui.java +++ b/src/main/java/Operations/Ui.java @@ -1,5 +1,7 @@ package Operations; +import Enums.TimeUnit; + /** * class to tell user about errors and completion of operations */ @@ -144,18 +146,11 @@ public void showChangeInTaskList() { System.out.println("You have some recurring tasks that need to be cleared, please check them:"); } - /** - * tells the user to input the amount of time to snooze the task - */ - public void showSnooze() { - System.out.println("Please indicate the amount of time you want to snooze this task"); - } - /** * tells the user that the requested task has been snoozed */ - public void showSnoozeComplete() { - System.out.println("Great I've snoozed your task"); + public void showSnoozeComplete(int index, int amount, TimeUnit unit) { + System.out.println("Great I've snoozed task " + index + " by " + amount + " " + unit.name()); } /** diff --git a/src/main/java/RoomShare.java b/src/main/java/RoomShare.java index 25d82701ad..455581c577 100644 --- a/src/main/java/RoomShare.java +++ b/src/main/java/RoomShare.java @@ -3,6 +3,7 @@ import Model_Classes.*; import Operations.*; +import java.io.FileNotFoundException; import java.util.ArrayList; /** @@ -65,7 +66,7 @@ public void run() throws RoomShareException { case help: help.helpCommandList(); help.showHelp(parser.getCommandLine()); - break; + break; case list: ui.showList(); @@ -76,7 +77,8 @@ public void run() throws RoomShareException { } pg = new ProgressBar(taskList.getSize(), taskList.getDoneSize()); pg.showBar(); - break; + break; + case bye: isExit = true; @@ -152,12 +154,10 @@ public void run() throws RoomShareException { case snooze : try { int index = parser.getIndex(); - TaskList.currentList().get(index); - ui.showSnooze(); int amount = parser.getAmount(); TimeUnit timeUnit = parser.getTimeUnit(); taskList.snooze(index, amount, timeUnit); - ui.showSnoozeComplete(); + ui.showSnoozeComplete(index + 1, amount, timeUnit); } catch (IndexOutOfBoundsException e) { ui.showIndexError(); } catch (IllegalArgumentException e) {