Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
a75fcee
build.gradle: Update version to 8.29
Aug 29, 2020
a47d697
Editted/added intro display
nowknowing Jan 21, 2021
868d263
Level 1 Greet, Echo, Exit
nowknowing Jan 21, 2021
40da541
Level 2 Add,List
nowknowing Jan 21, 2021
f7a9485
Level 2 compiled
nowknowing Jan 21, 2021
5c1e2d7
Level 3 - Mark as Done (with tick)
nowknowing Jan 22, 2021
277ea31
Editted to not list every time something is done. Only show what is d…
nowknowing Jan 22, 2021
286f0e6
removed Tasks class
nowknowing Jan 22, 2021
3c427af
Level 4 - todo,events,deadlines
nowknowing Jan 22, 2021
6d87412
Change tick to Cross
nowknowing Jan 27, 2021
217f18d
Edit full path to FC
nowknowing Jan 27, 2021
2da7257
Edit Formats at expected and boxes.
nowknowing Jan 27, 2021
7ce01bc
Add Delete Method.
nowknowing Jan 27, 2021
5ea0390
Combine exceptions handling. i.e. clean up
nowknowing Jan 29, 2021
83e25ad
Add Ui class in charge of reading and writing. Moved exception handin…
nowknowing Jan 30, 2021
a92c7bf
Edit Duke to remove Ui redundancies.
nowknowing Jan 30, 2021
bbed8dd
Add relevant packaging. remove .class
nowknowing Jan 30, 2021
2d4fffb
Add TaskList
nowknowing Jan 30, 2021
a97bea5
Reading from storage only. Add Parser and Storage class
nowknowing Jan 30, 2021
8edf5a9
Cleanup Duke. Add Storage read. Edit parser from 0 to X.
nowknowing Feb 1, 2021
83214d0
Gettable in task child classes. New info of task type. Markdone and u…
nowknowing Feb 1, 2021
b1c6137
Update Storage to markdone, delete, add new events.
nowknowing Feb 2, 2021
8060ea0
Empty parse from input method in Parser.java
nowknowing Feb 2, 2021
02d7dde
Merge branch 'branch-Level-7'
nowknowing Feb 2, 2021
82e1692
Add DateTime. Add DukeDateTimeException. Complete Level 8
nowknowing Feb 2, 2021
1cb4a2c
Merge branch 'branch-Level-8'
nowknowing Feb 2, 2021
d81a8ac
Add Handler. Edit Parser such that it only parses. Add checkDeleteDon…
nowknowing Feb 2, 2021
2c0ccfe
Add ParserTest(for input) and DukeTest(for checkDoneDeletePossible).
nowknowing Feb 3, 2021
e7c433d
Made a jar v0.1
nowknowing Feb 3, 2021
15ecb72
Add JavaDoc on tasks, Duke, Storage, Ui
nowknowing Feb 3, 2021
357647e
Add Find function
nowknowing Feb 3, 2021
87ee16c
Add Duke Exception comment
nowknowing Feb 4, 2021
43ee981
Merge branch 'banch-A-CodingStandard'
nowknowing Feb 4, 2021
c2494cb
Edit Coding Standard
nowknowing Feb 7, 2021
622cffe
Merge branch 'branch-A-CodingStandard'
nowknowing Feb 7, 2021
b4954a5
Commented on CommandHandler
nowknowing Feb 7, 2021
fe998fc
Comment on Parser Class.
nowknowing Feb 7, 2021
933c244
Merge branch 'branch-A-JavaDoc'
nowknowing Feb 7, 2021
0742e3b
Comment on FindHandler. Had forogotten to branch for level 9.
nowknowing Feb 7, 2021
004dd6d
Merge branch 'branch-Level-9'
nowknowing Feb 7, 2021
b066cc9
Change splitInput to splitInputs in Parser
nowknowing Feb 7, 2021
b7eae57
Fix coding standard issue
nowknowing Feb 7, 2021
c1158be
Merge remote-tracking branch 'origin/add-gradle-support'
nowknowing Feb 12, 2021
f839ecc
Merged gradle branch. Changed mainclassName.
nowknowing Feb 12, 2021
d0fd76b
Add Checkstyle. Edit code to meet standards.
nowknowing Feb 12, 2021
6b9e7ba
Add Gui. Level-10
nowknowing Feb 14, 2021
2506408
Merge branch 'branch-Level-10'
nowknowing Feb 14, 2021
1d9c26a
Add Checkstyle-IDEA plugin and fixes.
nowknowing Feb 14, 2021
7d6099f
Made fat JAR
nowknowing Feb 15, 2021
1c411b5
Improve codeQuality
nowknowing Feb 16, 2021
ec1cf9c
Remove assert.
nowknowing Feb 16, 2021
1e1920d
Add assert to getTask method
nowknowing Feb 16, 2021
f6bdb5f
Merge pull request #2 from nowknowing/Branch-A-CodeQuality
nowknowing Feb 16, 2021
7221b25
Merge branch 'master' into branch-A-Assertions
nowknowing Feb 16, 2021
a577fa0
Assert methods to getTask.
nowknowing Feb 16, 2021
1a5be77
Merge pull request #3 from nowknowing/branch-A-Assertions
nowknowing Feb 16, 2021
e532b61
Allow weekly recurring tasks for deadline and event.
nowknowing Feb 18, 2021
8dad726
Delete Ui.
nowknowing Feb 18, 2021
10f881f
Merge branch 'branch-RecurringTasks'
nowknowing Feb 18, 2021
7ece23f
Improve GUI
nowknowing Feb 18, 2021
d507f93
Change schedule input format.
nowknowing Feb 18, 2021
4a8e6c8
Delete data
nowknowing Feb 18, 2021
c1e705b
Add title Duke Luke Muke.
nowknowing Feb 19, 2021
df8672a
Add Readme UseGuide
nowknowing Feb 19, 2021
cc86996
Set theme jekyll-theme-modernist
nowknowing Feb 19, 2021
25557d1
New release
nowknowing Feb 19, 2021
418f1b7
Merge branch 'master' of https://github.com/nowknowing/ip
nowknowing Feb 19, 2021
78d7172
Set theme jekyll-theme-slate
nowknowing Feb 19, 2021
ab50e57
Add release hyperlink in readme.
nowknowing Feb 19, 2021
f43eca3
Update intro page README
nowknowing Feb 20, 2021
123ad30
Add pause.
nowknowing Feb 20, 2021
6c56882
New version
nowknowing Feb 20, 2021
1cd8274
Update readme link
nowknowing Feb 20, 2021
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.

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

import duke.exceptions.DukeException;
import duke.exceptions.DukeIDKException;
import duke.exceptions.DukeInvalidDesException;
import duke.exceptions.DukeMissingDesException;
import duke.handler.Parser;
import duke.handler.Queries;
import duke.tasks.*;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this import statement be listed explicitly instead?

import duke.tasks.Event;

import java.awt.*;
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 issue as above

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

public class Duke {
private boolean exit = false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

isExit

private Storage storage;
private TaskList tasks;
private Ui ui;

private Duke(String storagePath) {
storage = new Storage(storagePath);
tasks = storage.load();
ui = new Ui();
}

public static void main(String[] args) throws IOException {
new Duke("data/tasks.txt").run();
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 may want to use relative path

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi my understanding was that this already is a relative path.
What do you mean by use a "relative path"? could you suggest how this is done? Thank you.

}

public void run() {
ui.displayIntro();
while (exit == false) {
processInput(ui.readCommand());
}
ui.close();
}


private void processInput(String userInput) {
String keyword_UC = userInput.toUpperCase().split(" ", -1)[0];
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 use a camelCase variable name and a more descriptive name rather than UC here?

Queries query = Queries.ADD;
String response = "";

if (Queries.containsValue(keyword_UC)) {
query = Queries.valueOf(keyword_UC);
}

try {
switch (query) {
case BYE:
response = "Bye. Hope to see you again soon!";
ui.respond(response);
exit = true;
break;

case ADD:
Task toAdd;
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 may want to abstract each case into a separate method

try {
if (keyword_UC.equals("TODO")) {
toAdd = new Todo(userInput.split(" ", 2)[1]);
} else if (keyword_UC.equals("DEADLINE")) {
String[] info = userInput.split(" ", 2);
if (info[1].contains("/by")) {
info = info[1].split("/by");
} else {
throw new DukeInvalidDesException(keyword_UC);
}
toAdd = new Deadline(info[0], info[1]);
} else if (keyword_UC.equals("EVENT")) {
String[] info = userInput.split(" ", 2);
if (info[1].contains("/at")) {
info = info[1].split(("/at"));
} else {
throw new DukeInvalidDesException(keyword_UC);
}
toAdd = new Event(info[0], info[1]);
} else {
throw new DukeIDKException();
}
tasks.addTask(toAdd);
response = "Got it. I've added this task:\n"
+ " " + toAdd + "\n"
+ "Now you have " + tasks.getNumOfTasks() + " tasks in the list.\n";
ui.respond(response);
storage.addTask(toAdd);
} catch (ArrayIndexOutOfBoundsException e) {
throw new DukeMissingDesException(keyword_UC);
}
break;

case DONE:
try {
int taskNum = Integer.parseInt(userInput.split(" ")[1]);
tasks.markDone(taskNum);
Task updatedTask = tasks.getTask(taskNum);
response = "Nice! I've marked this task as done: \n"
+ " " + updatedTask+ "\n";
ui.respond(response);
storage.markDoneInStorage(updatedTask, taskNum);
} catch (ArrayIndexOutOfBoundsException e) {
throw new DukeMissingDesException("DONE");
} catch (IndexOutOfBoundsException | NumberFormatException e) {
throw new DukeInvalidDesException("DONE");
}
break;

case DELETE:
try {
int taskNum = Integer.parseInt(userInput.split(" ")[1]);
Task task = tasks.getTask(taskNum);
tasks.removeTask(taskNum);
response = "Noted. I've removed this task: \n"
+ " " + task + "\n";
ui.respond(response);
storage.delete(taskNum);
} catch (ArrayIndexOutOfBoundsException e) {
throw new DukeMissingDesException("DELETE");
} catch (IndexOutOfBoundsException | NumberFormatException e) {
throw new DukeInvalidDesException("DELETE");
}
break;
case LIST:
response += tasks.toString();
ui.respond(response);
break;
}
} catch (DukeException e) {
String output = e.getMessage();
ui.respond(output);
}

}


}

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

import duke.handler.Parser;
import duke.tasks.Deadline;
import duke.tasks.Event;
import duke.tasks.Task;
import duke.tasks.TaskList;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Scanner;

public class Storage {
private static String STORAGE_PATH;
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 this instance variable should be declared final instead? (as your variable name is already in all uppercase letters)

private static final int MARK_INDEX = 2;

public Storage(String storagePath) {
STORAGE_PATH = storagePath;
}

public TaskList load() {
TaskList tasks = new TaskList();
Scanner dataReader = null;
try{
File file = new File(STORAGE_PATH);
file.getParentFile().mkdirs();
file.createNewFile();

dataReader = new Scanner(file);
while (dataReader.hasNextLine()) {
Task task = Parser.parseFromData(dataReader.nextLine());
tasks.addTask(task);
}
return tasks;
} catch (IOException e) {
System.out.println("File did not load");
} finally {
dataReader.close();
}
return tasks;
}

public void addTask(Task task){
try {
FileWriter fw = new FileWriter(STORAGE_PATH, true);
String toWrite ="";
switch(task.getType()) {
case "TODO":
toWrite = String.format("%c|%c|%s",
'T',
task.isDone() ? 'X' : ' ',
task.getDescription());
break;
case "DEADLINE":
toWrite = String.format("%c|%c|%s|%s",
'D',
task.isDone() ? 'X' : ' ',
task.getDescription(),
((Deadline) task).getBy());
break;
case "EVENT":
toWrite = String.format("%c|%c|%s|%s",
'E',
task.isDone() ? 'X' : ' ',
task.getDescription(),
((Event) task).getAt());
break;
}
fw.write(toWrite + "\n");
fw.close();
} catch (IOException e) {
System.out.println("File could not be written to. Could not add task.");
}
}

public void markDoneInStorage(Task task, int taskNum) {
try {
Path path = Paths.get(STORAGE_PATH);
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
String line = lines.get(taskNum - 1);
StringBuilder updatedLine = new StringBuilder(line);
updatedLine.setCharAt(MARK_INDEX, 'X');
lines.set(taskNum - 1, updatedLine.toString());
Files.write(path, lines, StandardCharsets.UTF_8);
} catch (IOException e) {
System.out.println("Fail to mark done in storage file.");
}
}

public void delete(int taskNum) {
try {
Path path = Paths.get(STORAGE_PATH);
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
lines.remove(taskNum - 1);
Files.write(path, lines, StandardCharsets.UTF_8);
} catch (IOException e) {
System.out.println("Fail to delete item in storage file.");
}
}
}
59 changes: 59 additions & 0 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package duke;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Ui {
private static final String INDENT = " ";
private static final String TEXT_INDENT = INDENT + "|" + " ";
private static final String RES_BOX_TOP = INDENT + "_______________________________________________\n";
private static final String RES_BOX_BOTTOM = INDENT + "|____________________________________________\n"
+ INDENT + " \\|\n";
private static Scanner sc = new Scanner(System.in);
private final Scanner in;
private final PrintStream out;


public Ui() {
this.in = new Scanner(System.in);
this.out = System.out;
}

private boolean hasCommand() {
return in.hasNext();
}

public String readCommand() {
assert hasCommand();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Like the use of assertion here 😄

return in.nextLine();
}

public void close() {
in.close();
}

public void displayIntro() {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
String response = "Hello from\n"
+ logo + "\n"
+ "What can I do for you?\n";
respond(response);
}

public void respond(String response) {
String indentedResponse = Arrays.stream(response.split("\n"))
.map(line -> TEXT_INDENT + line)
.collect(Collectors.joining("\n")) + "\n";
String output = RES_BOX_TOP
+ indentedResponse
+ RES_BOX_BOTTOM;

System.out.println(output);
}
}
14 changes: 14 additions & 0 deletions src/main/java/duke/exceptions/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package duke.exceptions;

public class DukeException extends Exception{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should there be a space between Exception and the opening bracket {?

private String message = "OOPS!";

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

@Override
public String getMessage() {
return message;
}
}
23 changes: 23 additions & 0 deletions src/main/java/duke/exceptions/DukeIDKException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package duke.exceptions;

public class DukeIDKException extends DukeException{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should there be a space between DukeException and the opening bracket {?
I noticed the same issue in several other places too.

private String message;

/**
* Constructor for DukeException for incomprehensible request.
*/
public DukeIDKException() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DukeIdkException?

super("This is a Duke IDK exception");
message = super.getMessage() + " "
+ "I don't get what you mean.";
}

/**
* Returns message of the incomprehensible request.
* @return Message of the incomprehensible request.
*/
@Override
public String getMessage() {
return message;
}
}
Loading