Skip to content
Open
Show file tree
Hide file tree
Changes from 12 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
19 changes: 19 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Deadline extends Task {

protected String by;

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

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

@Override
public String getInitial() {
return "[D]";
}
}
47 changes: 41 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
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);
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) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Duke duke = new Duke("/data/tasks.txt");
duke.run();
}

}


6 changes: 6 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class DukeException extends RuntimeException {

public DukeException(String Message) {
super(Message);
}
}
19 changes: 19 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Event extends Task {

protected String at;

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

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

@Override
public String getInitial() {
return "[E]";
}
}
40 changes: 40 additions & 0 deletions src/main/java/FileClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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!");
}
}


}
}
129 changes: 129 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
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;

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 remove the indentation for the case clauses to follow the coding standards



}


}





}
51 changes: 51 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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;
}




}
53 changes: 53 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.util.ArrayList;

public class Task {
protected String description;
protected ArrayList<Boolean> isDone;

public Task(String description) {
this.description = description;
this.isDone = new ArrayList<Boolean>();
isDone.add(false);
}

public String getStatusIcon() {
return (isDone.get(0) ? "[X]" : "[ ]"); // mark done task with X // if done is "X" then " "
}

public void setAsDone() {
isDone.set(0, true);
}

public void setAsUndone() {
isDone.set(0, false);
}

public String marking(String mark) {
if (mark.equals("mark")) {
setAsDone();
String messageMarked = "Nice! I've marked this task as done: \n" +
this.toString() + "\n "
+ "=======================================";
return messageMarked;
} else {
setAsUndone();
String messageUnmarked = "OK, I've marked this task as not done yet: \n" +
this.toString() + "\n "
+ "=======================================";
return messageUnmarked;

}
}

public String toString() {
return getStatusIcon() + " " + this.description;
}

public String getInitial(){
return "Task";
}

public String getDescription() {
return description;
}
}
Loading