diff --git a/src/main/java/seedu/duke/Event.java b/src/main/java/seedu/duke/Event.java index abfb4ef453..662acf941a 100644 --- a/src/main/java/seedu/duke/Event.java +++ b/src/main/java/seedu/duke/Event.java @@ -27,7 +27,7 @@ public Event(String eventDescription, LocalDateTime start, boolean hasSt) { this.startTime = start; this.hasEndTime = false; this.hasStartTime = hasSt; - this.hasEndTime = false; + this.hasEndInfo = false; } public String getDescription() { @@ -78,7 +78,7 @@ public void changeTimeInfo(LocalDateTime start, boolean hasSt) { this.startTime = start; this.hasEndTime = false; this.hasStartTime = hasSt; - this.hasEndTime = false; + this.hasEndInfo = false; } public LocalDateTime getStartTime() { diff --git a/src/main/java/seedu/duke/EventList.java b/src/main/java/seedu/duke/EventList.java index 543e838cff..9eabd14f5d 100644 --- a/src/main/java/seedu/duke/EventList.java +++ b/src/main/java/seedu/duke/EventList.java @@ -29,15 +29,19 @@ public String getDetails(int index) { return taskList.get(index).toString(); } + public String getDescription(int index) { + return taskList.get(index).getDescription(); + } + + public String getTime(int index) { + return taskList.get(index).getTime(); + } + public void deleteThisTask(int index) { taskList.remove(index); listSize--; } - public ArrayList fullList() { - return this.taskList; - } - private LocalDateTime changeToDate(String time, String date) { String combination = date + " " + time; return LocalDateTime.parse(combination, dfWithTime); @@ -145,6 +149,15 @@ public int searchTaskIndex(String description) { } return -1; } + + public String getLastTaskDescription() { + return taskList.get(listSize-1).toString(); + } + + public void deleteAll() { + this.taskList = new ArrayList(); + this.listSize = 0; + } } final class TimeAndFlag { diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java index 7fc1be00fe..3fc648e77e 100644 --- a/src/main/java/seedu/duke/Parser.java +++ b/src/main/java/seedu/duke/Parser.java @@ -2,6 +2,8 @@ import java.util.Arrays; +// import javax.swing.plaf.basic.BasicTreeUI.SelectionModelPropertyChangeHandler; + public class Parser { private static final int OFFSET = 1; @@ -46,20 +48,37 @@ public static void parseCommand(String userInput, EventList eventList) { } private static void parseListCommand(EventList eventList) { - Ui.listTask(eventList.fullList()); + Ui.listTask(eventList.getFullList()); } - private static void parseDeleteCommand(String remainder, EventList eventList) { - eventList.deleteThisTask(Integer.parseInt(remainder) - OFFSET); - - //TODO: Show successful add on UI. (For all cases) - Ui.deleteSuccessMsg(); + private static void parseDeleteCommand(String remainder, EventList eventList) throws NPExceptions { + String[] details = remainder.split("-"); + + if(details.length <= 1) { + throw new NPExceptions("need a flag to specify your action!"); + } + + String information = details[1].substring(0,1).trim(); + if(information.equals("s")) { + int index = Integer.parseInt(details[1].substring(1).trim()) - OFFSET; + String deletedTask = eventList.getDetails(index); + eventList.deleteThisTask(index); + //TODO: Show successful add on UI. (For all cases) + Ui.deleteSuccessMsg(deletedTask); + } else if(details[1].substring(0,3).trim().equals("all")) { + eventList.deleteAll(); + Ui.deleteAllSuccess(); + } else { + throw new NPExceptions("please input a valid flag!"); + } + } private static void parseAddCommand(String remainder, EventList eventList) throws NPExceptions { // Method is still broken, someone will have to fix it fully later on when handling exceptions // Note no "-" anywhere else. String[] details = remainder.split("-"); + if(details.length <= 1) { throw new NPExceptions("Event description and start day of your event are strictly required!"); } @@ -103,7 +122,7 @@ private static void parseAddCommand(String remainder, EventList eventList) throw eventList.addEvent(eventName, startTime, startDate); } - Ui.addSuccessMsg(); + Ui.addSuccessMsg(eventList.getLastTaskDescription()); } private static void parseEditCommand(String remainder, EventList eventList) throws NPExceptions{ String[] details = remainder.split("-"); @@ -133,7 +152,6 @@ private static void parseEditCommand(String remainder, EventList eventList) thro throw new NPExceptions("Empty starting date detected! Please add starting date."); } else { int eventIndex = -1; - details[0] = details[0].trim(); try{ eventIndex = Integer.parseInt(details[0]); @@ -151,6 +169,7 @@ private static void parseEditCommand(String remainder, EventList eventList) thro } else { eventList.reviseTimeInfo(eventIndex, information[0], information[1]); } + Ui.editSuccessMsg(eventList.getDescription(eventIndex), eventList.getTime(eventIndex)); } } private static void addFormatChecker(String[] information) throws NPExceptions { diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index 4b24b972f7..2e7f09d5c4 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -5,20 +5,16 @@ public class Ui { /** - * Prints a line of dashes for - * better readability + * Prints a line of dashes for better readability */ public static void printDash() { System.out.println("____________________________________________________________"); } /** - * Obtains user input and interprets - * what needs to be performed by - * certain keywords. + * Obtains user input and interprets what needs to be performed by certain keywords. */ public static void getUserCommand(EventList eventList) { - Scanner in = new Scanner(System.in); String cmd; @@ -29,26 +25,25 @@ public static void getUserCommand(EventList eventList) { cmd = in.nextLine(); } + in.close(); } /** - * Prints a welcome message for - * users when application is launched + * Prints a welcome message for users when application is launched */ public static void showWelcome() { - String logo = "█▄ █ █ █ ▄▀▀ █▀▄ █ ▄▀▄ █▄ █ █▄ █ ██▀ █▀▄\n" - + "█ ▀█ ▀▄█ ▄██ █▀ █▄▄ █▀█ █ ▀█ █ ▀█ █▄▄ █▀▄\n\n"; + String logo = "???"; System.out.println(logo + "Hello there! What can we do for you today?"); printDash(); } /** - * Prints success message for - * users when event is added + * Prints success message for users when event is added */ - public static void addSuccessMsg() { + public static void addSuccessMsg(String taskDetail) { printDash(); - System.out.println("Event successfully added!"); + System.out.println("Event successfully added: "+System.lineSeparator()); + System.out.println(" > " + taskDetail); printDash(); } @@ -66,6 +61,7 @@ public static void addSuccessEditMsg() { * Prints error message for * users when there is unrecognised * command + * Prints error message for users when there is unrecognised command */ public static void addErrorMsg() { printDash(); @@ -73,23 +69,13 @@ public static void addErrorMsg() { printDash(); } - /** - * Prints error message for - * users with any error occurs + /* + * Prints success message for users when event is deleted */ - public static void printErrorMsg(String s){ + public static void deleteSuccessMsg(String taskDetail) { printDash(); - System.out.println(s); - printDash(); - } - - /** - * Prints success message for - * users when event is deleted - */ - public static void deleteSuccessMsg() { - printDash(); - System.out.println("Event(s) successfully deleted!"); + System.out.println("This event is deleted: "+System.lineSeparator()); + System.out.println(" > "+taskDetail); printDash(); } @@ -110,12 +96,30 @@ public static void listTask(ArrayList eventList) { } /** - * Prints an exit message when - * user intends to exit Duke + * Prints an exit message when user intends to exit Duke */ public static void printExit() { printDash(); System.out.println("Bye, see ya soon!"); printDash(); } + + public static void printErrorMsg (String errorMessage) { + printDash(); + System.out.println(errorMessage); + printDash(); + } + + public static void editSuccessMsg(String description, String time) { + printDash(); + System.out.println("Time of event: " + description + " is changed to: "); + System.out.println(" > " + time); + printDash(); + } + + public static void deleteAllSuccess() { + printDash(); + System.out.println(" > all events are deleted!"); + printDash(); + } } diff --git a/src/test/java/seedu/duke/ParserTest.java b/src/test/java/seedu/duke/ParserTest.java index 573dd672ba..89cfdc7dd1 100644 --- a/src/test/java/seedu/duke/ParserTest.java +++ b/src/test/java/seedu/duke/ParserTest.java @@ -20,7 +20,7 @@ void testParseAddCommand() { } @Test void testParserDeleteCOmmand(){ - parser.parseCommand("delete 1", eventList); + parser.parseCommand("delete -s 1", eventList); assert(eventList.getSize()==0); } // @Test diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index d499b87935..562a9882df 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,5 +1,2 @@ -█▄ █ █ █ ▄▀▀ █▀▄ █ ▄▀▄ █▄ █ █▄ █ ██▀ █▀▄ -█ ▀█ ▀▄█ ▄██ █▀ █▄▄ █▀█ █ ▀█ █ ▀█ █▄▄ █▀▄ - -Hello there! What can we do for you today? +???Hello there! What can we do for you today? ____________________________________________________________