Skip to content

Commit

Permalink
Level-8: Dates and Times
Browse files Browse the repository at this point in the history
  • Loading branch information
gx-huang committed Jan 28, 2020
1 parent da9be60 commit 52f5106
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/main/java/Deadlines.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import java.text.Format;
import java.text.SimpleDateFormat;
import java.time.LocalDate;

public class Deadlines extends Task{
protected String by;

Expand All @@ -8,11 +12,15 @@ public Deadlines(String description, Boolean isDone, String by) {
}

public String getDeadline() {
return this.by;
return this.by.toString();
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by:" + by + ")";
LocalDate date = LocalDate.parse(by);
Format formatter = new SimpleDateFormat("MMM");
String simpleMonth = date.getMonth().toString().substring(0,3);
String formattedDate = simpleMonth + " " + date.getDayOfMonth() + " " + date.getYear();
return "[D]" + super.toString() + "(by:" + formattedDate + ")";
}
}
22 changes: 12 additions & 10 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String logo = " _ ___________ ___________ _______ __ ____________ ________ ___ _____\n"
+ "| | |_ _| ___ \\ ___| ___ \\_ _\\ \\ / / | ___ \\ ___ \\_ _| \\/ || ___|\n"
+ "| | | | | |_/ / |__ | |_/ / | | \\ V / | |_/ / |_/ / | | | . . || |__ \n"
+ "| | | | | ___ \\ __|| / | | \\ / | __/| / | | | |\\/| || __|\n"
+ "| |_____| |_| |_/ / |___| |\\ \\ | | | | | | | |\\ \\ _| |_| | | || |___\n"
+ "\\_____/\\___/\\____/\\____/\\_| \\_| \\_/ \\_/ \\_| \\_| \\_|\\___/\\_| |_/\\____/\n";
System.out.println(logo);
System.out.println("LIBERTY PRIME IS ONLINE");
System.out.println("What can i do for you?");

Scanner input = new Scanner(System.in);

boolean isListening = true;
String filePath = "C:\\NUS\\Semester 4\\CS2103\\duke\\data\\duke.txt";
String filePath = "data\\duke.txt";
UserText tasks = new UserText(filePath);

while(isListening) {
Expand All @@ -26,7 +28,7 @@ public static void main(String[] args) {
try {

if (action.equalsIgnoreCase("bye")) {
System.out.println("Bye. Hope to see you again!");
System.out.println("DEATH IS A PREFERABLE ALTERNATIVE TO COMMUNISM");
tasks.saveTasks();
isListening = false;

Expand All @@ -46,7 +48,7 @@ public static void main(String[] args) {
} else if (action.equalsIgnoreCase(("deadline"))) {
System.out.println("Got it, I've added this task");
String context = command_broken[1];
String[] context_broken = context.split("/by", 2);
String[] context_broken = context.split(" /by ", 2);
tasks.addInput(new Deadlines(context_broken[0], false ,context_broken[1]));

} else if (action.equalsIgnoreCase(("todo"))) {
Expand All @@ -59,7 +61,7 @@ public static void main(String[] args) {
} else if (action.equalsIgnoreCase(("event"))) {
System.out.println("Got it, I've added this task");
String context = command_broken[1];
String[] context_broken = context.split("/at", 2);
String[] context_broken = context.split(" /at ", 2);
tasks.addInput(new Events(context_broken[0], false,context_broken[1]));

} else {
Expand Down

0 comments on commit 52f5106

Please sign in to comment.