Skip to content

Commit

Permalink
Merge branch 'branch-Level-8'
Browse files Browse the repository at this point in the history
  • Loading branch information
DerenC committed Feb 3, 2023
2 parents 0e21ec3 + 43e8e99 commit 72eb4cf
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 19 deletions.
20 changes: 15 additions & 5 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import java.time.LocalDateTime;

public class Deadline extends Task {
protected String by;
protected LocalDateTime by;

public Deadline(String description, String by, boolean isDone) {
public Deadline(String description, LocalDateTime by, boolean isDone){
super(description, isDone);
this.by = by;
this.by=by;
}

public Deadline(String description, String by) {
public Deadline(String description, LocalDateTime by) {
this(description, by, false);
}

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

public static String timeToString(LocalDateTime dateTime) {
String str = dateTime.toString();
if (str.substring(11).equals("12:34:56")) {
return str.substring(0, 10);
}
return str.substring(0, 10) + " " + str.substring(11, 16);
}

@Override
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import java.time.LocalDateTime;

public class Event extends Task {
protected String from;
protected String to;
protected LocalDateTime from;
protected LocalDateTime to;

public Event(String description, String from, String to, boolean isDone) {
public Event(String description, LocalDateTime from, LocalDateTime to, boolean isDone) {
super(description, isDone);
this.from = from;
this.to = to;
}

public Event(String description, String from, String to) {
public Event(String description, LocalDateTime from, LocalDateTime to) {
this(description, from, to, false);
}

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

public static String timeToString(LocalDateTime dateTime) {
String str = dateTime.toString();
if (str.substring(11).equals("12:34:56")) {
return str.substring(0, 10);
}
return str.substring(0, 10) + " " + str.substring(11, 16);
}

@Override
Expand Down
71 changes: 62 additions & 9 deletions src/main/java/Wessy.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;

public class Wessy {
static String OPENING_LINE = " -Wessy------------------------------" +
Expand Down Expand Up @@ -55,8 +56,8 @@ public static void main(String[] args) {
printMessage("☹ OOPS!!! It is not a number." +
" Please enter a number.");
} catch (ArrayIndexOutOfBoundsException ex) {
printMessage("☹ OOPS!!! Please enter a " +
"valid task number.");
printMessage("☹ OOPS!!! Please enter the " +
"correct format.");
}
}
}
Expand Down Expand Up @@ -123,6 +124,42 @@ static String[] parse(String description, CmdType type) throws
return new String[] {};
}

static LocalDateTime parseDateTime(String str) {
int n = str.length();
if (n <= 10) {
return LocalDateTime.parse(parseDate(str) + "T12:34:56");
}
int idx = 10;
if (str.charAt(9) == ' ') {
idx = 9;
} else if (str.charAt(8) == ' ') {
idx = 8;
}
if (str.charAt(idx + 3) == ':') {
return LocalDateTime.parse(parseDate(str.substring(0, idx)) + "T" + str.substring(idx + 1) + ":00");
}
if (str.charAt(idx + 3) == '.') {
return LocalDateTime.parse(parseDate(str.substring(0, idx)) + "T" + str.substring(idx + 1, idx + 3) + ":" + str.substring(idx + 4) + ":00");
}
return LocalDateTime.parse(parseDate(str.substring(0, idx)) + "T" + str.substring(idx + 1, idx + 3) + ":" + str.substring(idx + 3) + ":00");
}

static String parseDate(String str) {
String[] components = str.split("-", 3);
if (str.indexOf("/") != -1) {
components = str.split("/", 3);
}
for (int i = 0; i < components.length; i++) {
if (components[i].length() == 1) {
components[i] = "0" + components[i];
}
}
if (components[0].length() == 4) {
return components[0] + "-" + components[1] + "-" + components[2];
}
return components[2] + "-" + components[1] + "-" + components[0];
}

static boolean checkCmd(String userInput, CmdType type) {
int threshold = type.len();
return userInput.length() >= threshold && userInput.substring(0,
Expand Down Expand Up @@ -227,22 +264,38 @@ static void printAddedMessage(Task task) {

static void println(String str) {
int length = str.length();
String message = " | " + str;
for (int i = 0; i < 70 - length - 3; i++) {
message += " ";
if (length <= 64) {
String message = " | " + str;
for (int i = 0; i < 67 - length; i++) {
message += " ";
}
message += "|";
System.out.println(message);
} else {
System.out.println(" | " + str.substring(0, 64) + " |");
int remainingLength = length - 64;
int leftover = remainingLength % 62;
int n = (int) Math.floor(remainingLength/62);
for (int i = 0; i < n; i++) {
System.out.println(" | " + str.substring(62 * i, 62 * (i + 1)) + " |");
}
String message = " | " + str.substring(length - leftover);
for (int i = 0; i < 65 - leftover; i++) {
message += " ";
}
message += "|";
System.out.println(message);
}
message += "|";
System.out.println(message);
}

static Task addTask(String[] strings) {
int len = strings.length;
if (len == 1) {
tasks.add(new ToDo(strings[0]));
} else if (len == 2) {
tasks.add(new Deadline(strings[0], strings[1]));
tasks.add(new Deadline(strings[0], parseDateTime(strings[1])));
} else if (len == 3) {
tasks.add(new Event(strings[0], strings[1], strings[2]));
tasks.add(new Event(strings[0], parseDateTime(strings[1]), parseDateTime(strings[2])));
}
saveTasks();
return tasks.get(tasks.size() - 1);
Expand Down

0 comments on commit 72eb4cf

Please sign in to comment.