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

[Chan Jing Rong] Duke Increments #346

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
65f72a8
Add support for Gradle workflow
j-lum Aug 6, 2019
0112efe
Add sample checkstyle configuration
j-lum Aug 12, 2019
cfd6da7
Change file mode on `gradle` to be executable
j-lum Aug 18, 2019
6e6ace1
Merge pull request #12 from j-lum/gradle+x
j-lum Aug 18, 2019
a3ca5a4
Add configuration for console applications
j-lum Aug 20, 2019
7b60e81
Merge pull request #13 from j-lum/javaexec
j-lum Aug 21, 2019
3672239
Add scanner, lines and indentations. Echo commands
rongrongrr Aug 21, 2019
f7d21a1
Add arraylist to store tasks. Return appropriate output based on user…
rongrongrr Aug 21, 2019
2eeda50
Create Task class. Mark tasks as done
rongrongrr Aug 21, 2019
e711463
Convert Task class to abstract class. Implement Todo, Deadline and Ev…
rongrongrr Aug 22, 2019
cd13da7
Handle user input errors
rongrongrr Aug 22, 2019
bac973c
Implement delete function
rongrongrr Aug 22, 2019
96fc35c
Save tasks in hard disk
rongrongrr Aug 28, 2019
e5e16e2
Add date and time feature
rongrongrr Aug 29, 2019
66a6aa4
Resolve merge conflicts
rongrongrr Aug 29, 2019
acbe16b
Make the code more OOP
rongrongrr Sep 2, 2019
dbf905d
Add JUnit testing for Todo, Deadline, Parser, Duke (dummy test)
rongrongrr Sep 2, 2019
534fdfd
Implement find feature
rongrongrr Sep 4, 2019
be2b14f
Edit to match coding standard
rongrongrr Sep 4, 2019
d7c47a0
Add JavaDoc comments to code
rongrongrr Sep 4, 2019
daa3220
Merge conflicts
rongrongrr Sep 4, 2019
7a98b43
Merge conflicts
rongrongrr Sep 4, 2019
d469352
Merge branch 'gradle'
rongrongrr Sep 5, 2019
14d6de2
Set up Gradle
rongrongrr Sep 9, 2019
0c42333
Implement GUI
rongrongrr Sep 11, 2019
1598a4d
Add assertions (#4)
rongrongrr Sep 16, 2019
f4ff23a
Improve code quality (#5)
rongrongrr Sep 16, 2019
d4cfa86
Implement Undo command
rongrongrr Sep 18, 2019
a6cb27b
Finalise features
rongrongrr Sep 19, 2019
778e691
Finalise features and add cross-platform capabilities
rongrongrr Sep 30, 2019
3eeb423
Set up sample data
rongrongrr Sep 30, 2019
61d55fb
Add product representative screenshot
rongrongrr Sep 30, 2019
bf468af
Add User Guide
rongrongrr Sep 30, 2019
2ce87e7
Edit User Guide
rongrongrr Sep 30, 2019
656740f
Set theme jekyll-theme-cayman
rongrongrr Sep 30, 2019
ca6585d
Edit storage function
rongrongrr Sep 30, 2019
10548b3
Merge branch 'master' of https://github.com/rongrongrr/duke
rongrongrr Sep 30, 2019
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
Empty file added duke.txt
Empty file.
Binary file added src/main/java/Deadline.class
Binary file not shown.
74 changes: 74 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

/**
* Encapsulates a deadline to be stored in Duke.
*/
public class Deadline extends Task {
private String name;
private boolean done;

Choose a reason for hiding this comment

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

Should change done to isDone() to follow variable naming.

private Date by;
private SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy kkmm");

/**
* Creates a Deadline object tagged with name, whether it is completed, and task deadline.
*
* @param name Name of event.
* @param by Deadline by when task is due.
*/
public Deadline(String name, String by) {
super(name);
try {
this.by = format.parse(by);
} catch (ParseException e) {
e.printStackTrace();
}
}

/**
* Returns name of deadline.
*
* @return Name of deadline.
*/
public String getName() {
return super.getName();
}

/**
* Returns "y" or "n" based on completion of deadline.
*
* @return String "y" or "n".
*/
public String isDone() {
return super.isDone();
}

/**
* Returns deadline of task.
*
* @return Deadline of task in String format.
*/
public String getBy() {
return format.format(by);
}

/**
* Marks deadline as done.
*/
public void setDone() {
super.setDone();
}

/**
* Overrides the original toString method.
* Returns description of deadline as `[D][isDone] name (by: date)`.
*
* @return Formatted description of deadline.
*/
@Override
public String toString() {
return String.format("[D]%s (by: %s)", super.toString(), format.format(by));
}
}
Binary file added src/main/java/Duke.class
Binary file not shown.
59 changes: 53 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
import java.io.FileNotFoundException;
import java.io.IOException;

/**
* Encapsulates a Duke object for the execution of the Duke program.
*/
public class Duke {

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

/**
* Creates a Duke object tagged with ui, storage and list of tasks.
*
* @param filePath path of file to be used as storage.
*/
public Duke(String filePath) {
ui = new Ui();
try {
storage = new Storage(filePath);
} catch (FileNotFoundException e) {
ui.showError("filepath");
return;
}
try {
tasks = new TaskList(storage.load());
} catch (IOException e) {
ui.showError("load");
tasks = new TaskList();
}
}

/**
* Runs the Duke program.
*/
public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
ui.execute(tasks);
isExit = ui.isExit();
}

try {
storage.store();
} catch (IOException e) {
ui.showError("store");
}

ui.exit();
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke("/Users/jingrong/duke/duke.txt").run();
}
}
Binary file added src/main/java/Event.class
Binary file not shown.
69 changes: 69 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

/**
* Encapsulates an event to be stored in Duke.
*/
public class Event extends Task {
private String name;
private boolean done;
private Date at;
private SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy kkmm");

/**
* Creates an Event object tagged with name, whether it is completed, and event time.
*
* @param name Name of event.
* @param at Date of event.
*/
public Event(String name, String at) {
super(name);
try {
this.at = format.parse(at);
} catch (ParseException e) {
e.printStackTrace();
}
}

public String getName() {
return super.getName();
}

/**
* Returns "y" or "n" based on completion of event.
*
* @return String "y" or "n".
*/
public String isDone() {
return super.isDone();
}

/**
* Returns date of event.
*
* @return Date of event in String format.
*/
public String getAt() {
return format.format(at);
}

/**
* Marks event as done.
*/
public void setDone() {
super.setDone();
}

/**
* Overrides the original toString method.
* Returns description of event as `[E][isDone] name (at: date)`.
*
* @return Formatted description of event.
*/
@Override
public String toString() {
return String.format("[E]%s (at: %s)", super.toString(), format.format(at));
}
}
Binary file added src/main/java/Parser.class
Binary file not shown.
23 changes: 23 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Encapsulates a parser used to understand user commands.
*/
public class Parser {
private String[] commands;

/**
* Creates a Parser object.
*/
public Parser() {
}

Choose a reason for hiding this comment

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

You can choose not to type out the constructor method


/**
* Returns user commands parsed as a String array.
*
* @param command Command from user input.
* @return String array of split commands.
*/
public String[] parse(String command) {
commands = command.split(" ");
return commands;
}
}
Binary file added src/main/java/Storage.class
Binary file not shown.
85 changes: 85 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import java.util.ArrayList;

/**
* Encapsulates a Storage object to load and save tasks from and to file.
*/
public class Storage {
private String filePath;
private FileReader reader;
private BufferedReader bufferedReader;
private ArrayList<Task> tasks;

/**
* Creates a Storage object tagged with path of file, file reader, buffered reader, and list of tasks.
*
* @param filePath path of file for loading and saving of tasks.
* @throws FileNotFoundException If file is not found at specified location.
*/
public Storage(String filePath) throws FileNotFoundException {
this.filePath = filePath;
this.reader = new FileReader(this.filePath);
this.bufferedReader = new BufferedReader(reader);
this.tasks = new ArrayList<>();
}

/**
* Returns ArrayList of tasks loaded from file.
*
* @return ArrayList of tasks.
* @throws IOException If tasks failed to be retrieved.
*/
public ArrayList<Task> load() throws IOException {
String line = bufferedReader.readLine();
while (! (line == null)) {
String[] words = line.split(" , ");
Task task;
if (words[0].equals("T")) {
task = new Todo(words[2]);
} else if (words[0].equals("D")) {
task = new Deadline(words[2], words[3]);
} else {
task = new Event(words[2], words[3]);
}

Choose a reason for hiding this comment

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

Consider using switch if your if-else statements are long


if (words[1].equals("y")) {
task.setDone();
}

tasks.add(task);
line = bufferedReader.readLine();
}

return tasks;
}

/**
* Stores tasks in file.
*
* @throws IOException If tasks failed to be stored.
*/
public void store() throws IOException {
FileWriter writer = new FileWriter(this.filePath, false);
BufferedWriter bufferedWriter = new BufferedWriter(writer);

for (Task item : tasks) {
if (item instanceof Todo) {
bufferedWriter.write(String.format("T , %s , %s", item.isDone(), item.getName()));
} else if (item instanceof Deadline) {
bufferedWriter.write(String.format("D , %s , %s , %s", item.isDone(), item.getName(), ((Deadline) item)
.getBy()));
} else {
bufferedWriter.write(String.format("D , %s , %s , %s", item.isDone(), item.getName(), ((Event) item)
.getAt()));
}
bufferedWriter.newLine();
}
bufferedWriter.close();
}
}
Binary file added src/main/java/Task.class
Binary file not shown.
57 changes: 57 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Encapsulates a task to be stored in Duke.
*/
public abstract class Task {
private String name;
private boolean isDone;

/**
* Creates a Task object tagged with name and whether it is completed.
*
* @param name Name of task.
*/
public Task(String name) {
this.name = name;
this.isDone = false;
}

/**
* Returns "y" or "n" based on completion of task.
*
* @return String "y" or "n".
*/
public String isDone() {
if (isDone) {
return "y";
} else {
return "n";
}
}

/**
* Returns name of task.
*
* @return Name of task.
*/
public String getName() {
return name;
}

/**
* Marks task as done.
*/
public void setDone() {
isDone = true;
}

/**
* Overrides the original toString method.
* Returns description of task as `[isDone] name`.
*
* @return Formatted description of task.
*/
@Override
public String toString() {
Copy link
Member

Choose a reason for hiding this comment

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

Good work in abstracting common parts of code and using it in subclasses with super()

return String.format("[%s] %s", isDone(), name);
}
}
Binary file added src/main/java/TaskList.class
Binary file not shown.
Loading