Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2223S2#26 from hrithie/hrithieMenon-v1.0
Browse files Browse the repository at this point in the history
Update Duke & Expected
  • Loading branch information
matthew-liu-zhenjie authored Mar 13, 2023
2 parents 3993b81 + d744354 commit f1082ce
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 69 deletions.
25 changes: 8 additions & 17 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}

19 changes: 12 additions & 7 deletions src/main/java/seedu/duke/EventList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> taskList;
protected int listSize;

public EventList() {
this.taskList = new ArrayList<Event>();
this.listSize = 0;
Expand All @@ -34,6 +34,10 @@ public void deleteThisTask(int index) {
listSize--;
}

public ArrayList<Event> fullList() {
return this.taskList;
}

private LocalDateTime changeToDate(String time, String date) {
String combination = date + " " + time;
return LocalDateTime.parse(combination, dfWithTime);
Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -104,3 +108,4 @@ public ArrayList<Event> getFullList() {
return this.taskList;
}
}

101 changes: 56 additions & 45 deletions src/main/java/seedu/duke/Parser.java
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();
}
}
107 changes: 107 additions & 0 deletions src/main/java/seedu/duke/Ui.java
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();
}
}
1 change: 1 addition & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Hello from
|____/ \__,_|_|\_\___|

What is your name?
____________________________________________________________
Hello James Gosling

0 comments on commit f1082ce

Please sign in to comment.