From 3877b306098f327383afca9bb0a561f1b9b9d07d Mon Sep 17 00:00:00 2001 From: benitokun123 Date: Tue, 22 Oct 2019 00:00:31 +0800 Subject: [PATCH] change snooze to 1 line command --- src/main/java/Operations/Parser.java | 4 ++-- src/main/java/Operations/Storage.java | 2 +- src/main/java/Operations/TaskCreator.java | 28 ++++++++--------------- src/main/java/Operations/Ui.java | 13 ++++------- src/main/java/RoomShare.java | 9 ++++---- 5 files changed, 21 insertions(+), 35 deletions(-) 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..526ce5ac69 100644 --- a/src/main/java/Operations/Storage.java +++ b/src/main/java/Operations/Storage.java @@ -120,7 +120,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 dc48c49cfb..6c397537c9 100644 --- a/src/main/java/Operations/TaskCreator.java +++ b/src/main/java/Operations/TaskCreator.java @@ -120,26 +120,18 @@ 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; } } else throw new RoomShareException(ExceptionType.wrongTaskType); } 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 4fb22b57df..673c187777 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; /** @@ -62,7 +63,7 @@ public void run() throws RoomShareException { case help: help.helpCommandList(); help.showHelp(parser.getCommandLine()); - break; + break; case list: ui.showList(); @@ -71,7 +72,7 @@ public void run() throws RoomShareException { } catch (RoomShareException e) { ui.showWriteError(); } - break; + break; case bye: isExit = true; @@ -147,12 +148,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) {