Skip to content

Commit

Permalink
Merge branch 'branch-level-8'
Browse files Browse the repository at this point in the history
  • Loading branch information
huekoh committed Feb 6, 2024
2 parents aea83d7 + 383e95f commit b3a931f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 52 deletions.
41 changes: 31 additions & 10 deletions src/main/java/BMO.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.util.*;
import java.lang.*;
import java.time.format.DateTimeFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -60,25 +62,25 @@ static void parseData(String content) {
if (isDone) {
done(indexCounter.toString());
}
indexCounter ++;
indexCounter++;
break;
case "D":
String taskDueDate = info[3].trim();
addLog("deadline " + taskDescription + " /by " + taskDueDate);
if (isDone) {
done(indexCounter.toString());
}
indexCounter ++;
indexCounter++;
break;
case "E":
String taskStart = info[3].trim();
String taskEnd = info[4].trim();
addLog("event " + taskDescription + " /from " + taskStart
+ " /to " + taskEnd);
+ " /to " + taskEnd);
if (isDone) {
done(indexCounter.toString());
}
indexCounter ++;
indexCounter++;
break;
default:
System.out.println("Unknown task type: " + taskType);
Expand Down Expand Up @@ -150,13 +152,25 @@ static void salute() {
return;
}

static LocalDateTime formatDateTime(String input) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy HHmm");
return LocalDateTime.parse(input, formatter);
} catch (Exception e) {
System.out.println(Constants.errorPrint.erroneousAdd());
receive();
}

throw new IllegalArgumentException("Unrecognized date and time format: " + input);
}

static void addLog(String input) {
// create string formats for each task type for format checking
String deadlineFormat = "^deadline\\s+(\\w+(\\s+\\w+)*)\\s+/by\\s+(\\S+(\\s+\\w+)*)$";
String deadlineFormat = "^deadline\\s+(\\w+(\\s+\\w+)*)\\s+/by\\s+(\\S+(\\s+\\w+|/)*)$";
Pattern deadlinePattern = Pattern.compile(deadlineFormat);
Matcher deadlineMatcher = deadlinePattern.matcher(input);

String eventFormat = "^event\\s+(\\w+(\\s+\\w+)*)\\s+/from\\s+(\\S+(\\s+\\w+)*)\\s+/to\\s+(\\S+(\\s+\\w+)*)$";
String eventFormat = "^event\\s+(\\w+(\\s+\\w+)*)\\s+/from\\s+(\\S+(\\s+\\w+|/)*)\\s+/to\\s+(\\S+(\\s+\\w+|/)*)$";
Pattern eventPattern = Pattern.compile(eventFormat);
Matcher eventMatcher = eventPattern.matcher(input);

Expand All @@ -168,12 +182,19 @@ static void addLog(String input) {
if (deadlineMatcher.matches()) {
String task = deadlineMatcher.group(1);
String by = deadlineMatcher.group(3);
newTask = new Deadlines(task, by);

LocalDateTime byDateTime = formatDateTime(by);

newTask = new Deadlines(task, byDateTime);
} else if (eventMatcher.matches()) {
String task = eventMatcher.group(1);
String start = eventMatcher.group(3);
String end = eventMatcher.group(5);
newTask = new Events(task, start, end);

LocalDateTime startDateTime = formatDateTime(start);
LocalDateTime endDateTime = formatDateTime(end);

newTask = new Events(task, startDateTime, endDateTime);
} else if (toDoMatcher.matches()) {
String task = toDoMatcher.group(1);
newTask = new ToDos(task);
Expand All @@ -184,8 +205,8 @@ static void addLog(String input) {
System.out.println(Constants.errorPrint.todo());
} else if (input.startsWith("event")) {
System.out.println(Constants.errorPrint.event());
} else if (input.isBlank()){
System.out.println(Constants.errorPrint.emptyAdd());
} else if (input.isBlank()) {
System.out.println(Constants.errorPrint.erroneousAdd());
} else {
System.out.println(Constants.errorPrint.general());
}
Expand Down
73 changes: 39 additions & 34 deletions src/main/java/Constants.java
Original file line number Diff line number Diff line change
@@ -1,93 +1,98 @@
public class Constants {
public static final String introPrint = "-----------------------------------------\n"
public static final String introPrint = "----------------------------------------------------------------------------------\n"
+ " BMO chop!\n Do you want to play video games?\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";
public static final String tutorialPrint = "Command BMO with these keywords!\n"
+ "0. hi [greet BMO]\n"
+ "1. bye [shut BMO down]\n"
+ "2. log [view task log]\n"
+ "3. add todo <task> [add todo task]\n"
+ "4. add deadline <task> /by <date> [add deadline]\n"
+ "5. add event <event> /from <start> /to <end> [add event]\n"
+ "4. add deadline <task> /by <date> <time> [add deadline]\n"
+ "5. add event <event> /from <date> <time> /to <date> <time> [add event]\n"
+ "6. done <task number> [check task as done]\n"
+ "7. redo <task number> [uncheck task]\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";

public static final String hiPrint = "-----------------------------------------\n"
public static final String hiPrint = "----------------------------------------------------------------------------------\n"
+ " Good day! What can BMO help you with?\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";

public static final String byePrint = "-----------------------------------------\n"
public static final String byePrint = "----------------------------------------------------------------------------------\n"
+ " Beep boop BMO shutting down...\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";

public static final String emptyLogPrint = "-----------------------------------------\n"
public static final String emptyLogPrint = "----------------------------------------------------------------------------------\n"
+ " Wow! Your log is actually empty.\n"
+ " Let's play mario kart right now!!\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";

public static class errorPrint {
public static String general() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " BMO don't understand ;;;\n"
+ " You can refer to the command formats\n that appear when you switch me on. ^^\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";
}

public static String outOfRange() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " The index you have provided\n"
+ " is out of BMO's range!\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";
}

public static String alreadyDone() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " Are you playing with BMO's feelings >:(\n"
+ " The task is already done silly!\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";
}

public static String alreadyUnDone() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " Did you really think that task was already done...\n"
+ " You don't have to redo what you haven't even completed!\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";
}

public static String noInt() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " BMO needs to know the index of the task!\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";
}

public static String emptyAdd() {
return "-----------------------------------------\n"
public static String erroneousAdd() {
return "----------------------------------------------------------------------------------\n"
+ " If you want BMO to add a task to the log,\n"
+ " please use these formats:\n add todo <task>\n"
+ " add deadline <task> /by <due date>\n add event <task> /from <start> /to <end>\n"
+ "-----------------------------------------\n";
+ " please use these formats:\n\n"
+ " add todo <task>\n"
+ " add deadline <task> /by <date> <time>\n"
+ " add event <task> /from <date> <time> /to <date> <time>\n\n"
+ " acceptable datetime format: dd/MM/yyyy HHmm (example: 5/12/2024 1830)\n"
+ "----------------------------------------------------------------------------------\n";
}

public static String deadline() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " If you want BMO to record a deadline,\n"
+ " please input add deadline <task> /by <due date>\n"
+ "-----------------------------------------\n";
+ " please input add deadline <task> /by <date> <time>\n\n"
+ " acceptable datetime format: dd/MM/yyyy HHmm (example: 5/12/2024 1830)\n"
+ "----------------------------------------------------------------------------------\n";
}

public static String todo() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " If you want BMO to record a todo,\n"
+ " please input add todo <task>\n"
+ "-----------------------------------------\n";
+ "----------------------------------------------------------------------------------\n";
}

public static String event() {
return "-----------------------------------------\n"
return "----------------------------------------------------------------------------------\n"
+ " If you want BMO to record an event,\n"
+ " please input add event <task> /from <start> /to <end>\n"
+ "-----------------------------------------\n";
+ " please input add event <task> /from <date> <time> /to <date> <time>\n\n"
+ " acceptable datetime format: dd/MM/yyyy HHmm (example: 5/12/2024 1830)\n"
+ "----------------------------------------------------------------------------------\n";
}

}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/Deadlines.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Deadlines extends Task{

protected String by;
public Deadlines(String task, String by) {
protected LocalDateTime deadline;
public Deadlines(String task, LocalDateTime deadline) {
super(task);
this.by = by;
this.deadline = deadline;
}

public String getDeadline() {
return this.deadline.format(DateTimeFormatter.ofPattern("d' 'MMMM' 'yyyy', 'h:mma"));
}

@Override
Expand All @@ -14,7 +21,7 @@ public String toSaveData() {

@Override
public String toString() {
return "[D] " + super.toString() + " (by: " + by + ")";
return "[D] " + super.toString() + " (by: " + getDeadline() + ")";
}

}
19 changes: 15 additions & 4 deletions src/main/java/Events.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Events extends Task{

protected String start;
protected String end;
protected LocalDateTime start;
protected LocalDateTime end;

public Events(String task, String start, String end) {
public Events(String task, LocalDateTime start, LocalDateTime end) {
super(task);
this.start = start;
this.end = end;
}

public String getStart() {
return this.start.format(DateTimeFormatter.ofPattern("d' 'MMMM' 'yyyy', 'h:mma"));
}

public String getEnd() {
return this.end.format(DateTimeFormatter.ofPattern("d' 'MMMM' 'yyyy', 'h:mma"));
}

@Override
public String toSaveData() {
String done = super.getStatus() ? "1" : "0";
Expand All @@ -18,6 +29,6 @@ public String toSaveData() {

@Override
public String toString() {
return "[E] " + super.toString() + " (from: " + start + " to: " + end + ")";
return "[E] " + super.toString() + " (from: " + getStart() + " to: " + getEnd() + ")";
}
}

0 comments on commit b3a931f

Please sign in to comment.