Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cheng Deren] iP #367

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
7412db5
Add *.class to .gitignore
DerenC Jan 26, 2023
5b4ad51
Finish Level-1
DerenC Jan 26, 2023
1986f7c
Finish Level-2
DerenC Jan 26, 2023
2543b85
Change the chatbot's name from Duke to Wessy
DerenC Jan 26, 2023
fb30872
Improve the chatbot's opening message
DerenC Jan 26, 2023
fc5d2f9
Increase indentation to improve the appearance of the displayed message
DerenC Jan 27, 2023
fe4110b
Create 'Task' class
DerenC Jan 27, 2023
c1d02c0
Finish Level-3
DerenC Jan 28, 2023
f2b385f
Finish Level-4
DerenC Jan 30, 2023
17205ad
Clear up unused add functions
DerenC Jan 30, 2023
d444660
Finish Level-5
DerenC Jan 30, 2023
ba548a7
Modify EXPECTED.TXT & input.txt
DerenC Jan 30, 2023
6ef4659
Finish Level-6
DerenC Jan 30, 2023
6b4ecc8
Use enumerations instead of strings in Wessy (main driver) class
DerenC Jan 30, 2023
da15bb8
Complete checkstyle based on CS2030's standard
DerenC Jan 30, 2023
9cca35c
Finish Level-7
DerenC Feb 2, 2023
43e8e99
Finish Level-8
DerenC Feb 3, 2023
0e21ec3
Merge branch 'branch-Level-7'
DerenC Feb 3, 2023
72eb4cf
Merge branch 'branch-Level-8'
DerenC Feb 3, 2023
551cf7b
Merge remote-tracking branch 'remotes/origin/add-gradle-support'
DerenC Feb 3, 2023
388ae95
Initial setup of Gradle
DerenC Feb 5, 2023
4a61459
Finish A-MoreOOP
DerenC Feb 9, 2023
0a0f3f6
A-Packages
DerenC Feb 9, 2023
46e7bfe
Add JUnit test to test getCmd(), parseDateTime(), removeSpacePadding(…
DerenC Feb 9, 2023
88ec341
Create jar file for version release
DerenC Feb 9, 2023
8707b3e
Add Java documentation for some classes.
DerenC Feb 12, 2023
16f36ec
Finish A-CodingStandard
DerenC Feb 12, 2023
df037e7
Finish Level-9
DerenC Feb 12, 2023
a26aeeb
Merge branch 'branch-Level-9'
DerenC Feb 12, 2023
f8954a0
Merge branch 'branch-A-JavaDoc'
DerenC Feb 12, 2023
9ebbab9
Merge branch 'branch-A-CodingStandard'
DerenC Feb 12, 2023
98fa419
Add a basic GUI to Wessy
DerenC Feb 21, 2023
d387abf
Rename methods in Ui from prints to gets
DerenC Feb 21, 2023
cd2818d
Refactor the code by applying more OOP principle
DerenC Feb 9, 2023
d40651d
Merge commit 'cd2818dd855ef73b919892fe0703f1bef09f8db5'
DerenC Feb 21, 2023
8431958
Delete unnecessary java files outside the main.java.wessy directory
DerenC Feb 22, 2023
432a76b
Use Assertions
DerenC Feb 22, 2023
2a8e5da
Improve code quality
DerenC Feb 22, 2023
0bedb08
Use Streams
DerenC Feb 22, 2023
8da4963
Merge pull request #4 from DerenC/branch-A-Streams
DerenC Feb 22, 2023
ef63a64
Merge branch 'master' into branch-A-Assertions
DerenC Feb 22, 2023
e9b5032
Merge pull request #2 from DerenC/branch-A-Assertions
DerenC Feb 22, 2023
ea08add
Merge branch 'master' into branch-A-CodeQuality
DerenC Feb 22, 2023
370968f
Merge pull request #3 from DerenC/branch-A-CodeQuality
DerenC Feb 22, 2023
6bfaf73
Delete commented-out code used for Ui in Wessy.java
DerenC Feb 22, 2023
bce0f40
Declutter by deleting commented-out codes
DerenC Feb 22, 2023
35838ce
Comment out System.in as standardInput
DerenC Feb 23, 2023
8e57710
Implemented 2 extensions from category B
DerenC Feb 23, 2023
054a500
Add a User Guide
DerenC Feb 24, 2023
09999ca
Minor correction on phrasing of descrption of Feature #3
DerenC Feb 24, 2023
cda7911
Second minor correction on phrasing of descrption of Feature #3
DerenC Feb 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import java.time.LocalDateTime;

public class Deadline extends Task {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps can put this class into a package (like package duke), as other developers could better understand the code base when all the classes have been grouped in packages

protected String by;
protected LocalDateTime by;

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

@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);
}
}
18 changes: 14 additions & 4 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
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) {
public Event(String description, LocalDateTime from, LocalDateTime to) {
super(description);
this.from = from;
this.to = to;
}

@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);
}
}
73 changes: 64 additions & 9 deletions src/main/java/Wessy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;

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

static LocalDateTime parseDateTime(String str) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to store this parser into a seperate class

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 @@ -194,22 +233,38 @@ static void printAdded(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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to split this function into several to make it easier to edit in the future.

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 add(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])));
}
return tasks.get(tasks.size() - 1);
}
Expand Down