-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Bernard Wan De Yuan] iP #461
Open
bernardwan
wants to merge
40
commits into
nus-cs2103-AY2122S1:master
Choose a base branch
from
bernardwan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
d839859
Add Gradle support
f38a22a
Level-1
bernardwan b98c16f
Level-2
bernardwan feac61e
Level-3
bernardwan 83381b8
Level-4
bernardwan 3c1011c
Added automated text UI testing
bernardwan 7551481
Implemented Level-5, updated test cases
bernardwan 2565300
Implemented Level-6. updated tests
bernardwan 5ff4233
Implemented Level-7
bernardwan 0266c78
Implemented Level-8
bernardwan 33921a6
Merge branch 'branch-Level-8'
bernardwan 48d97f1
Updated tests
bernardwan 09721a2
Resolved conflict errors
bernardwan e4d0342
Refactor code to make it more OOP
bernardwan c3e9b99
Organise into package
bernardwan 6db07e9
Add Junit tests
bernardwan fe6833c
Create JAR File
bernardwan 5f6bf33
Add Javadocs
bernardwan 9dbf7dd
Tweak code to follow coding standard
bernardwan 06609b4
Implement Level-9 Find feature
bernardwan d093898
Merge branch 'branch-A-CodingStandard'
bernardwan d2d6805
Merge branch 'branch-Level-9'
bernardwan bcefd1c
Fix minor javadocs errors
bernardwan 679bfa8
Merge remote-tracking branch 'origin/add-gradle-support'
bernardwan 341051c
Add Gradle to project
bernardwan 5dcd832
Add ability to use checkstyle
bernardwan 62293f6
Add GUI
bernardwan c786acd
Modify config for proper Gradle usage
bernardwan 9d41498
Add Assert statements
bernardwan e710891
Check code for code quality and clean up code
bernardwan f787e9d
Merge pull request #1 from bernardwan/branch-A-Assertions
bernardwan 879b551
Merge branch 'master' into branch-A-CodeQuality
bernardwan 558ea60
Merge pull request #2 from bernardwan/branch-A-CodeQuality
bernardwan fceed2d
Implement B-DoWithinPeriodTasks
bernardwan fd12c10
Refactor code
bernardwan a57ca3c
Add User Guide
bernardwan d45e077
Rename boolean variable
bernardwan 6e830cf
Improve GUI
bernardwan 4714d9b
Handle some exceptions and change font
bernardwan 0d11fb8
Update README.md
bernardwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
todo | 0 | borrow book | ||
event | 0 | dinner with friends | 2021-12-03 | ||
todo | 1 | test test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
public class AddCommand extends Command{ | ||
private String type; | ||
private String description; | ||
|
||
public AddCommand(String type, String description) { | ||
this.type = type; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { | ||
Task task; | ||
if(type.equals("todo")) { | ||
task = new Task.Todo(description, false); | ||
|
||
} else if(type.equals("deadline")) { | ||
String[] temp = description.split("by ", 2); | ||
task = new Task.Deadline(temp[0], false, temp[1]); | ||
|
||
} else if(type.equals("event")) { | ||
String[] temp = description.split("at ", 2); | ||
task = new Task.Event(temp[0], false, temp[1]); | ||
|
||
} else { | ||
throw new DukeException("Sorry, I don't understand what that means. :("); | ||
} | ||
|
||
tasks.addTask(task); | ||
ui.print("Added: " + task.getTaskType() + task.getStatusIcon() + " " + task.getDescription()); | ||
ui.print("There are " + tasks.size() + " tasks in the list"); | ||
storage.save(tasks); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public abstract class Command { | ||
public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException; | ||
|
||
public abstract boolean isExit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class DeleteCommand extends Command{ | ||
|
||
private int index; | ||
|
||
public DeleteCommand(int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{ | ||
Task task = tasks.deleteTask(index); | ||
ui.print("Deleted:\n" + task.getDescription()); | ||
ui.print("There are " + tasks.size() + " tasks remaining in the list"); | ||
storage.save(tasks); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public class DoneCommand extends Command{ | ||
|
||
private int index; | ||
|
||
public DoneCommand(int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException{ | ||
Task task = tasks.doneTask(this.index); | ||
ui.print("Marked as done:\n" + task.getDescription()); | ||
storage.save(tasks); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,146 +1,41 @@ | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
System.out.println("Hello! I'm Magnolia\n" + "What can I do for you?"); | ||
Scanner sc = new Scanner(System.in); | ||
ArrayList<Task> list = new ArrayList<>(); | ||
try { | ||
File list_data = new File("data/duke.txt"); | ||
Scanner reader = new Scanner(list_data); | ||
while (reader.hasNextLine()) { | ||
String line = reader.nextLine(); | ||
String[] data = line.split(" \\| "); | ||
switch (data[0]) { | ||
case "todo": | ||
list.add(new Task.Todo(data[2], data[1].equals("0") ? false : true)); | ||
break; | ||
case "deadline": | ||
list.add(new Task.Deadline(data[2], data[1].equals("0") ? false : true, data[3])); | ||
break; | ||
case "event": | ||
list.add(new Task.Event(data[2], data[1].equals("0") ? false : true, data[3])); | ||
break; | ||
} | ||
} | ||
reader.close(); | ||
} catch (FileNotFoundException e) { | ||
File newFile = new File("data/duke.txt"); | ||
try { | ||
Files.createDirectories(Paths.get("data/")); | ||
newFile.createNewFile(); | ||
} catch (IOException a) { | ||
System.out.println("error"); | ||
a.printStackTrace(); | ||
} | ||
|
||
private Storage storage; | ||
private TaskList tasks; | ||
private Ui ui; | ||
|
||
public Duke() { | ||
ui = new Ui(); | ||
storage = new Storage("data/duke.txt"); | ||
try { | ||
tasks = new TaskList(storage.load()); | ||
} catch (DukeException e) { | ||
tasks = new TaskList(); | ||
} | ||
} | ||
|
||
while(true) { | ||
public void run() { | ||
ui.greet(); | ||
boolean isExit = false; | ||
while (!isExit) { | ||
try { | ||
String input = sc.nextLine(); | ||
String first_word = input.split(" ")[0]; | ||
|
||
|
||
if (input.equals("bye")) { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
break; | ||
} else if (input.equals("list")) { | ||
System.out.println("All tasks:"); | ||
int i = 1; | ||
for (Task item : list) { | ||
System.out.println(i + ". " + item.getTaskType() + item.getStatusIcon() + " " + item.getDescription()); | ||
i++; | ||
} | ||
|
||
} else if (first_word.equals("done")) { | ||
int index; | ||
try { | ||
index = Integer.parseInt(input.split(" ")[1]) - 1; | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
throw new DukeException("Sorry, please enter an integer after 'done'. (e.g. done 2)"); | ||
} | ||
Task temp; | ||
try { | ||
temp = list.get(index); | ||
} catch (IndexOutOfBoundsException e) { | ||
throw new DukeException("Sorry, there are only " + list.size() + " tasks."); | ||
} | ||
temp.setStatus(true); | ||
System.out.println("Marked as done:\n" + temp.getDescription()); | ||
save(list); | ||
|
||
} else if (first_word.equals("delete")) { | ||
int index; | ||
try { | ||
index = Integer.parseInt(input.split(" ")[1]) - 1; | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
throw new DukeException("Sorry, please enter an integer after 'delete'. (e.g. delete 2)"); | ||
} | ||
|
||
Task temp = list.get(index); | ||
System.out.println("Deleted:\n" + temp.getDescription()); | ||
list.remove(index); | ||
System.out.println("There are " + list.size() + " tasks remaining in the list"); | ||
save(list); | ||
} | ||
else { | ||
Task task = null; | ||
String remaining; | ||
try { | ||
remaining = input.split(" ", 2)[1]; | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
throw new DukeException("Sorry, tasks must include descriptions."); | ||
} | ||
if(first_word.equals("todo")) { | ||
task = new Task.Todo(remaining, false); | ||
|
||
} else if(first_word.equals("deadline")) { | ||
String[] temp = remaining.split("by ", 2); | ||
task = new Task.Deadline(temp[0], false, temp[1]); | ||
|
||
} else if(first_word.equals("event")) { | ||
String[] temp = remaining.split("at ", 2); | ||
task = new Task.Event(temp[0], false, temp[1]); | ||
|
||
} else { | ||
throw new DukeException("Sorry, I don't understand what that means. :("); | ||
} | ||
list.add(task); | ||
System.out.println("Added: " + task.getTaskType() + task.getStatusIcon() + " " + task.getDescription()); | ||
System.out.println("There are " + list.size() + " tasks in the list"); | ||
save(list); | ||
} | ||
String input = ui.readCommand(); | ||
Command c = Parser.parse(input); | ||
c.execute(tasks, ui, storage); | ||
isExit = c.isExit(); | ||
} catch (DukeException e) { | ||
ui.showError(e.getMessage()); | ||
} | ||
catch (DukeException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
public static void save(ArrayList<Task> list) { | ||
try { | ||
File list_data = new File("data/duke.txt"); | ||
FileWriter myWriter = new FileWriter(list_data); | ||
String data = ""; | ||
for (Task task : list) { | ||
data += task.toString() + "\n"; | ||
} | ||
myWriter.write(data); | ||
myWriter.close(); | ||
} catch (IOException e) { | ||
System.out.println("File not found"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
new Duke().run(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class ExitCommand extends Command{ | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class ListCommand extends Command{ | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) { | ||
ui.print("All tasks:"); | ||
ui.print(tasks.allTasks()); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
public class Parser { | ||
|
||
public static Command parse(String input) throws DukeException{ | ||
String first_word = input.split(" ")[0]; | ||
|
||
|
||
if (input.equals("bye")) { | ||
return new ExitCommand(); | ||
} else if (input.equals("list")) { | ||
return new ListCommand(); | ||
} else if (first_word.equals("done")) { | ||
int index; | ||
try { | ||
index = Integer.parseInt(input.split(" ")[1]) - 1; | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
throw new DukeException("Sorry, please enter an integer after 'done'. (e.g. done 2)"); | ||
} | ||
return new DoneCommand(index); | ||
} else if (first_word.equals("delete")) { | ||
int index; | ||
try { | ||
index = Integer.parseInt(input.split(" ")[1]) - 1; | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
throw new DukeException("Sorry, please enter an integer after 'delete'. (e.g. delete 2)"); | ||
} | ||
return new DeleteCommand(index); | ||
} | ||
else { | ||
String remaining; | ||
try { | ||
remaining = input.split(" ", 2)[1]; | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
throw new DukeException("Sorry, tasks must include descriptions."); | ||
} | ||
return new AddCommand(first_word, remaining); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class Storage { | ||
private String filepath; | ||
|
||
public Storage(String filepath) { | ||
this.filepath = filepath; | ||
} | ||
|
||
public ArrayList<Task> load() throws DukeException { | ||
ArrayList<Task> list = new ArrayList<>(); | ||
File list_data = new File(filepath); | ||
Scanner reader; | ||
try { | ||
reader = new Scanner(list_data); | ||
} catch (FileNotFoundException e) { | ||
throw new DukeException("File not found"); | ||
} | ||
|
||
while (reader.hasNextLine()) { | ||
String line = reader.nextLine(); | ||
String[] data = line.split(" \\| "); | ||
switch (data[0]) { | ||
case "todo": | ||
list.add(new Task.Todo(data[2], data[1].equals("0") ? false : true)); | ||
break; | ||
case "deadline": | ||
list.add(new Task.Deadline(data[2], data[1].equals("0") ? false : true, data[3])); | ||
break; | ||
case "event": | ||
list.add(new Task.Event(data[2], data[1].equals("0") ? false : true, data[3])); | ||
break; | ||
} | ||
} | ||
reader.close(); | ||
return list; | ||
} | ||
|
||
public void save(TaskList list) { | ||
try { | ||
File list_data = new File(filepath); | ||
Files.createDirectories(Paths.get("data/")); | ||
FileWriter myWriter = new FileWriter(list_data); | ||
myWriter.write(list.toString()); | ||
myWriter.close(); | ||
} catch (IOException e) { | ||
System.out.println("File not found"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to consider setting
isExit
toFalse
in the abstract, then only changing it toTrue
when it is an ExitCommand. This way you do not have to constantly check what Command it is