Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
5406049
Level-1
KristopherPTaslim Jan 21, 2022
0dd972e
Finish Level-2
KristopherPTaslim Jan 21, 2022
1812262
Finish Level-3
KristopherPTaslim Jan 21, 2022
277c43f
Finish Level-4
KristopherPTaslim Jan 21, 2022
73b1d1c
Finish Level-5
KristopherPTaslim Jan 22, 2022
d619a83
Finish Level-6
KristopherPTaslim Jan 22, 2022
318b3aa
Finish Testing
KristopherPTaslim Jan 23, 2022
32bb23a
Finish Branch-Level-7
KristopherPTaslim Jan 29, 2022
bc9608c
Finish branch-Level-8
KristopherPTaslim Jan 29, 2022
e754bcb
Merge branch 'branch-Level-8'
KristopherPTaslim Jan 29, 2022
b37f27b
Debug Branch Level-7
KristopherPTaslim Jan 29, 2022
83bb0f3
Finish A-MOREOOP
KristopherPTaslim Feb 6, 2022
27fc406
Finish A-Packages
KristopherPTaslim Feb 6, 2022
589b161
Finish A-JUnit
KristopherPTaslim Feb 7, 2022
e8b6b2a
Debug A-JUnit
KristopherPTaslim Feb 7, 2022
28a85db
Delete the wrong folder test:java:duke
KristopherPTaslim Feb 7, 2022
7bbe7be
Finish A-Javadoc
KristopherPTaslim Feb 8, 2022
7b43639
Added missing JavaDoc in the branch-A-JavaDoc
KristopherPTaslim Feb 8, 2022
bbc3057
Finish A-CodingStandard
KristopherPTaslim Feb 9, 2022
6ea1b8c
Finish branch-Level-9
KristopherPTaslim Feb 9, 2022
3d551ba
Merge tag 'branch-A-CodingStandard'
KristopherPTaslim Feb 9, 2022
452a916
Merge tag 'branch-Level-9'
KristopherPTaslim Feb 9, 2022
aa60d80
Merging all the three branches(JavaDoc, Coding Standard and Level 9)
KristopherPTaslim Feb 9, 2022
6b75a3c
Merge commit 'd8398594b7bc43da5eb865321c5a50cec4b3923d' into branch-A…
KristopherPTaslim Feb 10, 2022
725a458
Finish running branch-A-Gradle
KristopherPTaslim Feb 10, 2022
fd68d86
Finish Level-10
KristopherPTaslim Feb 14, 2022
80a985b
Fix Minor Bug
KristopherPTaslim Feb 14, 2022
4524860
Edit execute() method in Parser class to follow coding standard.
KristopherPTaslim Feb 15, 2022
adc7846
Add assertions in some various points in code
KristopherPTaslim Feb 16, 2022
c3d28a2
Merge pull request #2 from KristopherPTaslim/branch-A-Assertions
KristopherPTaslim Feb 16, 2022
97d12b1
Merge branch 'master' into branch-A-CodeQuality
KristopherPTaslim Feb 16, 2022
1dfa71f
Merge pull request #3 from KristopherPTaslim/branch-A-CodeQuality
KristopherPTaslim Feb 16, 2022
c96d62b
Edit minor feature in Parser class
KristopherPTaslim Feb 16, 2022
36ccfcc
Finish branch-BCD-Extension
KristopherPTaslim Feb 18, 2022
99300b0
Add Ui.png under the docs folder
KristopherPTaslim Feb 18, 2022
7e5a187
Update ReadME.md
KristopherPTaslim Feb 18, 2022
cc38eb8
Update ReadME.md
KristopherPTaslim Feb 18, 2022
1a329c8
Edit some parts in build.gradle
KristopherPTaslim Feb 19, 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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package duke;

class Deadline extends Task {

protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}
Comment on lines +7 to +10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you could rename "by" to something more descriptive.

Suggested change
public Deadline(String description, String by) {
super(description);
this.by = by;
}
public Deadline(String description, String deadlineDate) {
super(description);
this.deadlineDate = deadlineDate;
}


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

@Override
public String getInitial() {
return "[D]";
}
}
47 changes: 47 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package duke;

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

public class Duke {

private Storage storage;
private TaskList taskList;
private Ui ui;

public Duke(String filePath) {
this.ui = new Ui();
this.storage = new Storage(filePath);
this.taskList = new TaskList(storage);
}

public void run() {
ui.showWelcomeMessage();
try {
Scanner sc = new Scanner(storage.load());
String input = sc.nextLine();
Parser parser = new Parser(taskList);

while (sc.hasNextLine()) {
parser.execute(input);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

perhaps you can change the name of the method since a parser is parsing an input

Suggested change
parser.execute(input);
parser.parseInput(input);

if (input.toLowerCase().equals("bye")) {
break;
}
input = sc.nextLine();
}

} catch (IOException e) {
System.out.println("File is not found :(!");
}

storage.writeFile();
}

public static void main(String[] args) {
Duke duke = new Duke("/data/tasks.txt");
duke.run();
}

}


8 changes: 8 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package duke;

class DukeException extends RuntimeException {

public DukeException(String Message) {
super(Message);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could add a more descriptive message to be stored within the DukeException class

}
21 changes: 21 additions & 0 deletions src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package duke;

class Event extends Task {

protected String at;

public Event(String description, String at) {
super(description);
this.at = at;
}
Comment on lines +7 to +10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same thing with the deadline task

Suggested change
public Event(String description, String at) {
super(description);
this.at = at;
}
public Event(String description, String eventDate) {
super(description);
this.eventDate= eventDate;
}


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

@Override
public String getInitial() {
return "[E]";
}
}
42 changes: 42 additions & 0 deletions src/main/java/duke/FileClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package duke;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;

class FileClass {

public void createFile(String filePath) {
File f = new File(filePath); //initialise the file
if (!f.exists()) { //meaning f doesnt exist
try {
f.createNewFile();
} catch (IOException e) {
System.out.println("Path Directory is invalid!");
}
}
}
//taken from W3.3c File Access
public void writeFile(String filePath, String textToAdd) throws IOException {
FileWriter fw = new FileWriter(filePath, true); // initialise the filewriter
fw.write(textToAdd + "\r\n");
fw.close();
}

public void createDirectory(String filePath) {
File f = new File(filePath); //initialise the file
Path path = Paths.get(filePath);
if (!f.exists()) { //meaning f doesnt exist
try {
Files.createDirectory(path);
} catch (IOException e) {
System.out.println("Path Directory cannot be created!");
}
}


}
}
131 changes: 131 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package duke;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

class Parser {
public TaskList taskList;
private Ui ui;

Parser(TaskList taskList) {
this.taskList = taskList;
this.ui = new Ui();
}

public void execute(String input) {
String[] checkCase = input.split(" ");
switch (checkCase[0].toLowerCase()) {

case ("list"):
ui.showListMessage(taskList);
break;

case ("mark"):
try {
int index = Integer.parseInt(checkCase[1]) - 1;
Task tasks = taskList.getTaskArray().get(index);
System.out.println(tasks.marking(checkCase[0].toLowerCase()));
taskList.getTaskArray().set(index, tasks);
} catch (ArrayIndexOutOfBoundsException e) {
ui.showInvalidInput();
}
break;

case ("unmark"):
try {
int index = Integer.parseInt(checkCase[1]) - 1;
Task tasks = taskList.getTaskArray().get(index);
System.out.println(tasks.marking(checkCase[0].toLowerCase()));
taskList.getTaskArray().set(index, tasks);
} catch (ArrayIndexOutOfBoundsException e) {
ui.showInvalidInput();
}
break;

case ("todo"):

try {
String toDoCondition = "todo ";
int indexOfToDo = toDoCondition.length(); //to find todo
String stringSliced = input.substring(indexOfToDo,input.length());
Todo todoTask = new Todo(stringSliced);
taskList.addTask(todoTask);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showAddedMessage(todoTask, noOfTask);
} catch (StringIndexOutOfBoundsException e) {
ui.showTodoError();
}
break;

case ("deadline"):

try {
String deadlineCondition = "/by ";
int indexOfTime = input.indexOf(deadlineCondition); //to find /
String dateTime = input.substring(indexOfTime + deadlineCondition.length(), input.length()); // the date and time for by
//convert to the correct one
LocalDateTime deadlineTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = deadlineTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));
String stringSliced = input.substring(9, indexOfTime); // after deadline
Deadline deadlineTask = new Deadline(stringSliced, convertedTime);
taskList.addTask(deadlineTask);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showAddedMessage(deadlineTask, noOfTask);
} catch (StringIndexOutOfBoundsException e) {
ui.showDeadlineError();
}
break;

case ("event"):

try {
String eventCondition = "/at ";
int indexOfTime = input.indexOf(eventCondition); //to find /
String dateTime = input.substring(indexOfTime + eventCondition.length(), input.length()); // the date and time for at
//convert to the correct one
LocalDateTime eventTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = eventTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));
String stringSliced = input.substring(6, indexOfTime); // after deadline
Event eventTask = new Event(stringSliced, convertedTime);
taskList.addTask(eventTask);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showAddedMessage(eventTask, noOfTask);

} catch (StringIndexOutOfBoundsException e) {
ui.showEventError();
}
break;

case("delete"):

try {
int index = Integer.parseInt(checkCase[1]) - 1;
Task task = taskList.getTaskArray().get(index);
taskList.deleteTask(index);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showDeletedMessage(task, noOfTask);
} catch (ArrayIndexOutOfBoundsException e) {
ui.showDeleteError();
}
break;

case("bye"):
ui.showGoodbyeMessage();
break;

default:
ui.showDefaultMessage();
break;



}


}
Comment on lines +17 to +157
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apart from the coding standard violations, perhaps you can break up each case instruction into separate methods for increased readability?

For example:

public void delete() {
    try {
                    int index = Integer.parseInt(checkCase[1]) - 1;
                    Task task = taskList.getTaskArray().get(index);
                    taskList.deleteTask(index);
                    String noOfTask = String.valueOf(taskList.getTaskArray().size());
                    ui.showDeletedMessage(task, noOfTask);
                } catch (ArrayIndexOutOfBoundsException e) {
                    ui.showDeleteError();
                }
}






}
53 changes: 53 additions & 0 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package duke;

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

class Storage {
private ArrayList<Task> taskArray;
private String path;
private static String HOME = System.getProperty("user.home");

Storage(String path) {
this.taskArray = new ArrayList<Task>();
this.path = path;
}

public File load() {
FileClass fc = new FileClass(); //file class
String homePath = HOME + "/data";
path = HOME + path;
fc.createDirectory(homePath); //create directory first
fc.createFile(path); //create a file in the /home/data/tasks.txt
File file = new File(path);
return file;
}

public void writeFile() {
FileClass fc = new FileClass();
String filePath = HOME + "/data/stored.txt";
fc.createFile(filePath);
for (int i = 0; i < taskArray.size(); i++) {
Task tasks = taskArray.get(i);
try {
String firstInitial = tasks.getInitial() ; //first initial character
String textToAdd = firstInitial + " | " + tasks.getStatusIcon() + " | "
+ taskArray.get(i).getDescription();
fc.writeFile(filePath, textToAdd);
} catch (IOException e) {
System.out.println("File is not found :(!");
}

}

}

public ArrayList<Task> getList() {
return this.taskArray;
}




}
Binary file added src/main/java/duke/Task.class
Binary file not shown.
Loading