Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change snooze to 1 line command #85

Merged
merged 4 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/Operations/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Operations/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public ArrayList<Task> loadFile(String fileName) throws RoomShareException {
}
}
}
} catch (IOException | ArrayIndexOutOfBoundsException e) {
} catch (IOException | IndexOutOfBoundsException e) {
throw new RoomShareException(ExceptionType.wrongFormat);
}
return (taskArrayList);
Expand Down
36 changes: 12 additions & 24 deletions src/main/java/Operations/TaskCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions src/main/java/Operations/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
13 changes: 4 additions & 9 deletions src/main/java/Operations/Ui.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package Operations;

import Enums.TimeUnit;

/**
* class to tell user about errors and completion of operations
*/
Expand Down Expand Up @@ -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());
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/RoomShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Model_Classes.*;
import Operations.*;

import java.io.FileNotFoundException;
import java.util.ArrayList;

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ public void run() throws RoomShareException {
case help:
help.helpCommandList();
help.showHelp(parser.getCommandLine());
break;
break;

case list:
ui.showList();
Expand All @@ -76,7 +77,8 @@ public void run() throws RoomShareException {
}
pg = new ProgressBar(taskList.getSize(), taskList.getDoneSize());
pg.showBar();
break;
break;


case bye:
isExit = true;
Expand Down Expand Up @@ -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) {
Expand Down