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 11 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.
33 changes: 33 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;

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;

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

public Deadline(String name, String by) {
super(name);
try {
this.by = format.parse(by);
} catch (ParseException e) {
e.printStackTrace();
}
}

public String getBy() {
return format.format(by);
}

public void mark() {
super.mark();
}

@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.
49 changes: 43 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

public class Duke {

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

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();
}
}

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.
33 changes: 33 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;

public class Event extends Task {
private String name;
private boolean done;
private Date at;

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

public Event(String name, String at) {
super(name);
try {
this.at = format.parse(at);
} catch (ParseException e) {
e.printStackTrace();
}
}

public String getAt() {
return format.format(at);
}

public void mark() {
super.mark();
}

@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.
12 changes: 12 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Parser {
private String[] commands;

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


public String[] parse(String command) {
commands = command.split(" ");
return commands;
}
}
Binary file added src/main/java/Storage.class
Binary file not shown.
61 changes: 61 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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;

public class Storage {
private String filePath;
private FileReader reader;
private BufferedReader bufferedReader;
private ArrayList<Task> tasks;

public Storage(String filePath) throws FileNotFoundException {
this.filePath = filePath;
this.reader = new FileReader(this.filePath);
this.bufferedReader = new BufferedReader(reader);
this.tasks = new ArrayList<>();
}

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.mark();
}

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

return tasks;
}

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.getMark(), item.getName()));
} else if (item instanceof Deadline) {
bufferedWriter.write(String.format("D , %s , %s , %s", item.getMark(), item.getName(), ((Deadline) item).getBy()));
} else {
bufferedWriter.write(String.format("D , %s , %s , %s", item.getMark(), item.getName(), ((Event) item).getAt()));
}
bufferedWriter.newLine();
}
bufferedWriter.close();
}
}
Binary file added src/main/java/Task.class
Binary file not shown.
37 changes: 37 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public abstract class 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.

Done can be renamed isDone

Choose a reason for hiding this comment

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

Name and done should be protected instead, so that classes that extends it can use it


public Task(String name) {
this.name = name;
this.done = false;
}

public String getMark() {
if (done) {
return "y";
} else {
return "n";
}
}

public String getName() {
return name;
}

public void mark() {
done = true;
}

@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()

String mark;
if (done) {
mark = "y";
} else {
mark = "n";
}

return String.format("[%s] %s", mark, name);
}
}
Binary file added src/main/java/TaskList.class
Binary file not shown.
29 changes: 29 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.ArrayList;

public class TaskList {
private ArrayList<Task> tasks;

public TaskList(ArrayList<Task> tasks) {
this.tasks = tasks;
}

public TaskList() {
this.tasks = new ArrayList<>();
}

public void add(Task task) {
tasks.add(task);
}

public void delete(int index) {
tasks.remove(index);
}

public void done(int index) {
tasks.get(index).mark();
}

public ArrayList<Task> getTasks() {
return tasks;
}
}
Binary file added src/main/java/Todo.class
Binary file not shown.
17 changes: 17 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Todo 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 not recreate a new private variable in Todo. Instead use Task's protected isDone and name


public Todo(String name) {
super(name);
}

public void mark() {
super.mark();
}

@Override
public String toString() {
return String.format("[T]%s", super.toString());

Choose a reason for hiding this comment

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

I like the use of String.format() here

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