From b7db0d0fcca7451dc49097bed1c00ec32d820078 Mon Sep 17 00:00:00 2001 From: hrithie Date: Mon, 13 Mar 2023 18:40:41 +0800 Subject: [PATCH 1/2] Update Duke, EventList, Parser, Ui --- src/main/java/seedu/duke/Duke.java | 25 ++---- src/main/java/seedu/duke/EventList.java | 19 +++-- src/main/java/seedu/duke/Parser.java | 101 ++++++++++++---------- src/main/java/seedu/duke/Ui.java | 107 ++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 69 deletions(-) create mode 100644 src/main/java/seedu/duke/Ui.java diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 118f896e16..aeda6f6f91 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,6 +1,6 @@ package seedu.duke; -import java.util.Scanner; +// import java.util.Scanner; //import seedu.duke.ui.Ui; //import seedu.duke.EventList; //import seedu.duke.parser.Parser; @@ -22,25 +22,16 @@ public void run(){ //ui.showWelcome(); //boolean isExit = false; //while(!isExit){ - //String fullCommand = ui.getUserCommand(); - //parser.parseInput(fullCommand, tasks); - //if (fullCommand.equalsIgnoreCase("bye")){ - //isExit = true; - //} + //String fullCommand = ui.getUserCommand(); + //parser.parseInput(fullCommand, tasks); + //if (fullCommand.equalsIgnoreCase("bye")){ + //isExit = true; + //} //} } public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); - - Scanner in = new Scanner(System.in); - System.out.println("Hello " + in.nextLine()); + Ui.showWelcome(); + Ui.printExit(); } } - diff --git a/src/main/java/seedu/duke/EventList.java b/src/main/java/seedu/duke/EventList.java index c5286b6ce0..bbfc518817 100644 --- a/src/main/java/seedu/duke/EventList.java +++ b/src/main/java/seedu/duke/EventList.java @@ -7,10 +7,10 @@ public class EventList { private static final String DTINIT = "2000/01/01 01:01"; private static DateTimeFormatter dfWithTime = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); - + protected ArrayList taskList; protected int listSize; - + public EventList() { this.taskList = new ArrayList(); this.listSize = 0; @@ -34,6 +34,10 @@ public void deleteThisTask(int index) { listSize--; } + public ArrayList fullList() { + return this.taskList; + } + private LocalDateTime changeToDate(String time, String date) { String combination = date + " " + time; return LocalDateTime.parse(combination, dfWithTime); @@ -44,20 +48,20 @@ private LocalDateTime changeToDate(String date) { } /** * For two addEvent funcs below: - * if user doesn't input endDay(which means there is also no endTime), + * if user doesn't input endDay(which means there is also no endTime), * you can just call .addEvent(description, startTime, startDay) - * + * * I also make the specific time(hh:mm) optional, so if user doesn't input the specfic time, * you can just pass an empty String to that param and it will handle the rest things * e.g. addEvent(descrption, "", startDay, "", endDay) * addEvent(descrption, "", startDay, endTime, endDay) * addEvent(descrption, "", startDay) * so only startDay is strictly required. - * + * * and the same for reviseTimeInfo() */ public void addEvent(String description, String startTime, String startDay, String endTime, - String endDay) { + String endDay) { boolean hasStTime = true; boolean hasEdTime = true; @@ -83,7 +87,7 @@ public void addEvent(String description, String startTime, String startDay, Stri listSize++; } - public void addEvent(String description, String startTime, String startDay) { + public void addEvent(String description, String startTime, String startDay, String endTime) { boolean hasStTime = true; LocalDateTime combinedStartTime = LocalDateTime.parse(DTINIT, dfWithTime); @@ -104,3 +108,4 @@ public ArrayList getFullList() { return this.taskList; } } + diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java index 9b1271f30a..e3c1edba66 100644 --- a/src/main/java/seedu/duke/Parser.java +++ b/src/main/java/seedu/duke/Parser.java @@ -1,45 +1,56 @@ -// package seedu.duke; - -// public class Parser { - - -// public static void parseCommand(String userInput, EventList eventList){ -// userInput = userinput.trim(); -// String command = userInput.substring(0, userInput.indexOf(" ")); -// String remainder = userInput.substring(userInput.indexOf(" ")+ 1); -// switch (command) { -// case "add": -// parseAddCommand(remainder); -// break; -// case "delete": -// parseDeleteCommand(remainder); -// break; -// case "list": - -// break; -// case "edit": - -// break; -// default: - -// break; -// } -// } - -// private static void parseAddCommand(String remainder) { -// //Note no - anywhere else. -// String[] details = remainder.split("-"); -// String eventName = details[0]; -// String startTime = details[1]; -// String startDate = details[2]; -// String endTime = details[3]; -// if (details.length == 5){ -// String endDate = details[4]; -// EventList.add(eventName, startTime, startDate, endTime, endDate); -// } -// else{ -// EventList.add(eventName, startTime, startDate, endTime); -// } -// //TODO: Show successful add on UI. (For all cases) -// } -// } +package seedu.duke; + +public class Parser { + + public static void parseCommand(String userInput, EventList eventList) { + userInput = userInput.trim(); + String command = userInput.substring(0, userInput.indexOf(" ")); + String remainder = userInput.substring(userInput.indexOf(" ") + 1); + switch (command) { + case "add": + parseAddCommand(remainder, eventList); + break; + case "delete": + parseDeleteCommand(remainder, eventList); + break; + case "list": + parseListCommand(eventList); + break; + case "edit": + // parseEditCommand(); + default: + Ui.addErrorMsg(); + break; + } + } + + private static void parseListCommand(EventList eventList) { + Ui.listTask(eventList.fullList()); + } + + private static void parseDeleteCommand(String remainder, EventList eventList) { + eventList.deleteThisTask(Integer.parseInt(remainder)); + + //TODO: Show successful add on UI. (For all cases) + Ui.deleteSuccessMsg(); + } + + private static void parseAddCommand(String remainder, EventList eventList) { + // Note no "-" anywhere else. + String[] details = remainder.split("-"); + String eventName = details[0]; + String startTime = details[1]; + String startDate = details[2]; + String endTime = details[3]; + + if (details.length == 5) { + String endDate = details[4]; + eventList.addEvent(eventName, startTime, startDate, endTime, endDate); + } else { + eventList.addEvent(eventName, startTime, startDate, endTime); + } + + //TODO: Show successful add on UI. (For all cases) + Ui.addSuccessMsg(); + } +} diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java new file mode 100644 index 0000000000..a9f0518b89 --- /dev/null +++ b/src/main/java/seedu/duke/Ui.java @@ -0,0 +1,107 @@ +package seedu.duke; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Ui { + /** + * 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. + */ + public static void getUserCommand(EventList eventList) { + + Scanner in = new Scanner(System.in); + + String cmd; + cmd = in.nextLine(); + + while (!(cmd.equals("bye"))) { + Parser.parseCommand(cmd, eventList); + cmd = in.nextLine(); + } + + } + + /** + * Prints a welcome message for + * users when application is launched + */ + public static void showWelcome() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + System.out.println("What is your name?"); + printDash(); + Scanner in = new Scanner(System.in); + System.out.println("Hello " + in.nextLine()); + } + + /** + * Prints success message for + * users when event is added + */ + public static void addSuccessMsg() { + printDash(); + System.out.println("Event successfully added!"); + printDash(); + } + + /** + * Prints error message for + * users when there is unrecognised + * command + */ + public static void addErrorMsg() { + printDash(); + System.out.println("Sorry, I don't understand you!"); + printDash(); + } + + /** + * Prints success message for + * users when event is deleted + */ + public static void deleteSuccessMsg() { + printDash(); + System.out.println("Event successfully deleted!"); + printDash(); + } + + /** + * Prints list of events + */ + public static void listTask(ArrayList taskList) { + printDash(); + if (taskList.size() == 0) { + System.out.println("There are no events!"); + printDash(); + return; + } + for (int i = 0; i < taskList.size(); i++) { + System.out.println(" > " + Integer.toString(i + 1) + "." + taskList.get(i).toString()); + } + printDash(); + } + + /** + * Prints an exit message when + * user intends to exit Duke + */ + public static void printExit() { + printDash(); + System.out.println("Bye, see ya soon!"); + printDash(); + } +} From d74435483c803d80238b52d2d738468add707754 Mon Sep 17 00:00:00 2001 From: hrithie Date: Mon, 13 Mar 2023 18:55:15 +0800 Subject: [PATCH 2/2] Update Duke & Expected --- src/main/java/seedu/duke/Duke.java | 2 +- text-ui-test/EXPECTED.TXT | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index aeda6f6f91..e53349bd9a 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -32,6 +32,6 @@ public void run(){ public static void main(String[] args) { Ui.showWelcome(); - Ui.printExit(); + // Ui.printExit(); } } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 892cb6cae7..a32dfa2ade 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -6,4 +6,5 @@ Hello from |____/ \__,_|_|\_\___| What is your name? +____________________________________________________________ Hello James Gosling