forked from nus-cs2113-AY2223S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2113-AY2223S2#26 from hrithie/hrithieMenon-v1.0
Update Duke & Expected
- Loading branch information
Showing
5 changed files
with
184 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Event> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters