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

[Ng Hong Liang] iP #277

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d669ce5
Level 1. Greet,Echo,Exit
jinnhl Jan 20, 2022
254eda2
Level2. Add,List
jinnhl Jan 20, 2022
7723b25
Level 3. Mark as Done
jinnhl Jan 20, 2022
959058b
Level 4. ToDos,Events,Deadlines
jinnhl Jan 20, 2022
c80dda2
A-TextUiTesting done
jinnhl Jan 20, 2022
301de33
Polished the comments in Todo, Deadline and Event
jinnhl Jan 20, 2022
efc711e
Level 5. Handle Erros
jinnhl Jan 20, 2022
78ac805
Converted the storage type from Array to Arraylist + added delete fun…
jinnhl Jan 20, 2022
c61e079
Updated some testcases
jinnhl Jan 27, 2022
8239eb6
Added read and write feature
jinnhl Jan 27, 2022
dc1b29d
Added better formatting for date and time
jinnhl Jan 27, 2022
3fa0f96
Merge branch 'branch-Level-7'
jinnhl Jan 27, 2022
237e571
Merge branch 'branch-Level-8'
jinnhl Jan 27, 2022
e866177
Add classes for A-MoreOOP
jinnhl Feb 6, 2022
6f2f008
Organize into Packages
jinnhl Feb 6, 2022
5d00070
Add JUnit tests
jinnhl Feb 7, 2022
4dd3896
Add JavaDoc comments
jinnhl Feb 8, 2022
9d7baf3
Merge branch 'branch-A-JavaDoc'
jinnhl Feb 8, 2022
afb83cb
Tweak the code to comply with a coding standard
jinnhl Feb 9, 2022
3e3cd51
Merge branch 'branch-A-CodingStandard'
jinnhl Feb 9, 2022
a519396
Add more information to JavaDoc in command package
jinnhl Feb 9, 2022
2b1a9ea
Add find feature
jinnhl Feb 9, 2022
36c4d6d
Merge branch 'branch-Level-9'
jinnhl Feb 9, 2022
63fee40
Use Gradle
jinnhl Feb 16, 2022
6792f7f
Merge branch 'A-gradle'
jinnhl Feb 16, 2022
19ea522
Add GUI
jinnhl Feb 17, 2022
230e6e4
Merge branch 'branch-Level-10'
jinnhl Feb 17, 2022
a84882c
Add Assertions
jinnhl Feb 17, 2022
c18be9f
Improve Code Quality
jinnhl Feb 17, 2022
d606b75
Merge pull request #2 from jinnhl/branch-A-Assertions
jinnhl Feb 17, 2022
33769db
Merge branch 'master' into branch-A-CodeQuality
jinnhl Feb 17, 2022
115306b
Merge pull request #3 from jinnhl/branch-A-CodeQuality
jinnhl Feb 17, 2022
2c63595
Add notes feature
jinnhl Feb 17, 2022
87d3f89
Merge branch 'branch-D-Notes'
jinnhl Feb 17, 2022
884d070
Improve GUI
jinnhl Feb 17, 2022
e81148b
Add a User Guide
jinnhl Feb 18, 2022
09de543
Release v0.2
jinnhl Feb 18, 2022
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Binary files
*.class
*.jar
*.exe

# IDEA files
/.idea/
/out/
Expand Down
6 changes: 6 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
T | 1 | read book
D | 0 | return book | June 6th
E | 0 | project meeting | Aug 6th 2-4pm
T | 1 | join sports club
D | 0 | return book | Sunday
E | 0 | project meeting | Mon 2-4pm
4 changes: 4 additions & 0 deletions data/dukee.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
T | 1 | read book
D | 0 | return book | June 6th
E | 0 | project meeting | Aug 6th 2-4pm
T | 1 | join sports club
71 changes: 71 additions & 0 deletions src/main/java/DateParse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.time.format.DateTimeFormatter;

Choose a reason for hiding this comment

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

Perhaps consider separating similar ones into blocks?


/**
* This class parse a varying format of dates into a LocalDate object.
*/

public class DateParse {
private LocalDate date;
private boolean isFound = false;
ArrayList<DateTimeFormatter> knownPatterns = new ArrayList<DateTimeFormatter>();
DateTimeFormatter format1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter format2 = DateTimeFormatter.ofPattern("yyyy/MM/dd");
DateTimeFormatter format3 = DateTimeFormatter.ofPattern("yyyy-MM-d");
DateTimeFormatter format4 = DateTimeFormatter.ofPattern("yyyy/MM/d");
DateTimeFormatter format5 = DateTimeFormatter.ofPattern("yyyy-M-d");
DateTimeFormatter format6 = DateTimeFormatter.ofPattern("yyyy/M/d");
DateTimeFormatter format7 = DateTimeFormatter.ofPattern("yyyy-M-dd");
DateTimeFormatter format8 = DateTimeFormatter.ofPattern("yyyy/M/dd");
DateTimeFormatter format9 = DateTimeFormatter.ofPattern("dd-MM-yyyy");
DateTimeFormatter format10 = DateTimeFormatter.ofPattern("dd/MM/yyyy");
DateTimeFormatter format11 = DateTimeFormatter.ofPattern("d-MM-yyyy");
DateTimeFormatter format12 = DateTimeFormatter.ofPattern("d/MM/yyyy");
DateTimeFormatter format13 = DateTimeFormatter.ofPattern("d-M-yyyy");
DateTimeFormatter format14 = DateTimeFormatter.ofPattern("d/M/yyyy");
DateTimeFormatter format15 = DateTimeFormatter.ofPattern("dd-M-yyyy");
DateTimeFormatter format16 = DateTimeFormatter.ofPattern("dd/M/yyyy");

public DateParse(String str) {
knownPatterns.add(format1);
knownPatterns.add(format2);
knownPatterns.add(format3);
knownPatterns.add(format4);
knownPatterns.add(format5);
knownPatterns.add(format6);
knownPatterns.add(format7);
knownPatterns.add(format8);
knownPatterns.add(format9);
knownPatterns.add(format10);
knownPatterns.add(format11);
knownPatterns.add(format12);
knownPatterns.add(format13);
knownPatterns.add(format14);
knownPatterns.add(format15);
knownPatterns.add(format16);

int curr = 0;
while((!isFound) && curr < 16) {
try {
date = LocalDate.parse(str, knownPatterns.get(curr));
isFound = true;
} catch (DateTimeParseException e) {
curr++;
}
}
if ((!isFound) && curr == 16) {
System.err.println("Format not found");
}
this.helper();
}

private LocalDate helper() {

Choose a reason for hiding this comment

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

maybe can use getDate here? 😄

return date;
}

public String toString() {
return date.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
}
}
32 changes: 32 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Deadline extends Task {
protected String dateInfo;
protected DateParse date;
protected TimeParse time;

/**
* Constructor for Deadline class
Copy link

Choose a reason for hiding this comment

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

Might be better to put a line after the JavaDoc descriptor and the params?

* @param description Name of the Deadline
* @param dateInfo Information for which this task is due
*/
public Deadline(String description, String dateInfo) {
super(description);
String[] str = dateInfo.split(" ", 2);
this.date = new DateParse(str[0]);
this.time = new TimeParse(str[1]);
this.dateInfo = this.date.toString() + " " + this.time.toString();
}

public String whatType() {

Choose a reason for hiding this comment

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

Perhaps consider naming the method with verbs such as 'getType()'?

return "D";
}

/**
* toString method specific for Deadline class,
* inherits toString() fromTask class while adding additional information
* Like the type of task, [D], and date information
*/
@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + this.dateInfo + ")";
}
}
106 changes: 100 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,104 @@
import java.io.FileNotFoundException;
Copy link

Choose a reason for hiding this comment

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

Can consider putting your Duke.java in a package?

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {
/**
* main functions like a to-do list
*/
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Scanner scanner = new Scanner(System.in);
String input = "";
Boolean end = false;

Choose a reason for hiding this comment

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

Perhaps use a name that sounds more like a boolean? What about something like 'isEnd' or 'isExited'?

ArrayList<Task> store = new ArrayList(100);

Choose a reason for hiding this comment

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

Perhaps consider using a plural noun as the name of the ArrayList?


try {
new ReadFile(store);
} catch (FileNotFoundException e) {
System.err.println(e);
System.exit(0);
}

int curr = store.size();
System.out.println("Hello! I'm Duke\nWhat can I do for you?");

// While loop ends when user inputs bye
while(!end) {
input = scanner.nextLine();
String[] splitInput = input.split(" ", 2);

Choose a reason for hiding this comment

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

Perhaps consider using a plural noun as a variable name here?

try {
new DukeException().checker(splitInput, curr);
} catch (DukeException e) {
System.err.println(e);
continue;
}
// If user inputs bye, terminate the program
if (input.equals("bye")) {
end = true;
}
Copy link

Choose a reason for hiding this comment

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

Good use of in-line comments, they adhere to the coding standard's requirement as well

Choose a reason for hiding this comment

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

Agreed! I like how you use in-line comments to help in code readability and understanding the code :)

// If user inputs list, run through the to-do list, array store[], and list out all the to-dos
else if (input.equals("list")) {
for (int n = 0; n < curr; n++) {
int temp = n + 1;
System.out.println(temp + "." + store.get(n).toString());
}
}
// If user inputs keyword mark, mark the task corresponding to the index number as done
else if (splitInput[0].equals("mark")) {
Integer num = Integer.parseInt(splitInput[1]) - 1;
store.get(num).setMark();
System.out.println("Nice! I've marked this task as done:\n " + store.get(num).toString());
}
// If user inputs keyword unmark, mark the task corresponding to the index number as not done
else if (splitInput[0].equals("unmark")){
Integer num = Integer.parseInt(splitInput[1]) - 1;
store.get(num).setUnmark();
System.out.println("OK, I've marked this task as not done yet:\n " + store.get(num).toString());
}
// If user inputs keyword to-do, add this task as a Todo class
else if (splitInput[0].equals("todo")) {
store.add(new Todo(splitInput[1]));
int temp = curr + 1;
System.out.println("Got it. I've added this task:\n " + store.get(curr).toString()
+ "\nNow you have " + temp + " tasks in the list.");
curr++;
}
// If user inputs keyword deadline, add this task as a Deadline class
else if (splitInput[0].equals("deadline")) {
String[] splitInput2 = splitInput[1].split(" /by ", 2);
store.add(new Deadline(splitInput2[0], splitInput2[1]));
int temp = curr + 1;
System.out.println("Got it. I've added this task:\n " + store.get(curr).toString()
+ "\nNow you have " + temp + " tasks in the list.");
curr++;
}
// If user inputs keyword event, add this task as an Event class
else if (splitInput[0].equals("event")) {
String[] splitInput2 = splitInput[1].split(" /at ", 2);
store.add(new Event(splitInput2[0], splitInput2[1]));
int temp = curr + 1;
System.out.println("Got it. I've added this task:\n " + store.get(curr).toString()
+ "\nNow you have " + temp + " tasks in the list.");
curr++;
}
// If user inputs keyword delete, delete the task corresponding to the index given
else if (splitInput[0].equals("delete")) {
Integer num = Integer.parseInt(splitInput[1]) - 1;
curr--;
System.out.println("Noted. I've removed this task:\n " + store.get(num).toString()
+ "\nNow you have " + curr + " tasks in the list.");
store.remove(num);
}
// Unused
else {}
}
System.out.println("Bye. Hope to see you again soon!");
try {
new WriteFile(store);
} catch (IOException e) {
e.printStackTrace();
}
}
}

89 changes: 89 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* DukeException class is a custom exception class to handle
* problems that might occur in Duke.java
*/
public class DukeException extends Exception {

public DukeException(String errorMessage) {
super(errorMessage);
}

public DukeException() {}

/**
* checker method is used to run checks for all the different types of request
* and check if it invalids any of them. Returns a description or advice on what
* is missing or how to resolve it.
* @param arr This String array stores the user's input, used to check for validity
* @param curr Holds the capacity for the stored list, used to check if request is out of bounds
* @throws DukeException
*/
public void checker(String[] arr, int curr) throws DukeException {

Choose a reason for hiding this comment

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

maybe can use a more descriptive name for the method 😄
e.g
commandChecker
stringChecker
inputTester

String request = arr[0];
int len = arr.length;
if (request.equals("delete")) {
if (len == 1) {
throw new DukeException(" ☹ OOPS!!! Please tell me the task's" +
" index number so that I can delete it from the list.");
} else {
Integer index = Integer.parseInt(arr[1]);
if (index < 1 || index > curr) {
throw new DukeException(" ☹ OOPS!!! The task you want to delete is out of bounds," +
" please double check the index number");
}
}
} else if (request.equals("mark")) {
if (len == 1) {
throw new DukeException(" ☹ OOPS!!! Please tell me the task's" +
" index number so that I can mark it as done.");
} else {
Integer index = Integer.parseInt(arr[1]);
if (index < 1 || index > curr) {
throw new DukeException(" ☹ OOPS!!! The task you want to mark as done is out of bounds," +
" please double check the index number");
}
}
} else if (request.equals("unmark")) {
if (len == 1) {
throw new DukeException("☹ OOPS!!! Please tell me the task's\" +\n" +
" \" index number so that I can mark it as not done.");
} else {
Integer index = Integer.parseInt(arr[1]);
if (index < 1 || index > curr) {
throw new DukeException(" ☹ OOPS!!! The task you want to mark as not done is out of bounds," +
" please double check the index number");
}
}
} else if (request.equals("todo")) {
if (len == 1) {
throw new DukeException(" ☹ OOPS!!! The description of a todo cannot be empty.");
}
} else if (request.equals("deadline")) {
if (len == 1) {
throw new DukeException(" ☹ OOPS!!! The description of a deadline cannot be empty.");
} else {
String[] components = arr[1].split("/by", 2);
if (components[0].equals("") || components[0].equals(" ")) {
throw new DukeException(" ☹ OOPS!!! The description of a deadline cannot be empty.");
} else if (components.length == 1 || components[1].equals("") || components[1].equals(" ")) {
throw new DukeException(" ☹ OOPS!!! Please input a due date for this task");
} else {}
}
} else if (request.equals("event")) {
if (len == 1) {
throw new DukeException(" ☹ OOPS!!! The description of a event cannot be empty.");
} else {
String[] components = arr[1].split("/at", 2);
if (components[0].equals("") || components[0].equals(" ")) {
throw new DukeException(" ☹ OOPS!!! The description of a event cannot be empty.");
} else if (components.length == 1 || components[1].equals("") || components[1].equals(" ")) {
throw new DukeException(" ☹ OOPS!!! Please input a due date for this task");
} else {}
}
} else if (request.equals("bye") || request.equals("list")) {}
else {
throw new DukeException(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n " +
" Please add a valid request");
}
}
}
32 changes: 32 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Event extends Task {
protected String dateInfo;
protected DateParse date;
protected TimeParse time;

/**
* Constructor for Event class
* @param description Name of the Event
* @param dateInfo Information for which this task is due
*/
public Event(String description, String dateInfo) {
super(description);
String[] str = dateInfo.split(" ", 2);
this.date = new DateParse(str[0]);
this.time = new TimeParse(str[1]);
this.dateInfo = this.date.toString() + " " + this.time.toString();
}

public String whatType() {
return "E";
}

/**
* toString method specific for Event class,
* inherits toString() fromTask class while adding additional information
* Like the type of task, [E], and date information
*/
@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + this.dateInfo + ")";
}
}
Loading