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

[Lawnce Goh] Duke Increments #347

Open
wants to merge 75 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
75 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
8658615
Level-1. Greet, Echo, Exit
lawncegoh Aug 18, 2019
24141dc
Level-2. Add, List
lawncegoh Aug 18, 2019
31173af
Level-3. Mark as Done
lawncegoh Aug 18, 2019
a2c727d
Level 4. ToDos, Events, Deadlines
lawncegoh Aug 19, 2019
7957c13
Level-5. Handle Errors
lawncegoh Aug 20, 2019
d5a61de
Level-6. Delete
lawncegoh Aug 20, 2019
183dfe7
Level-5. Handle Errors
lawncegoh Aug 22, 2019
37ec8a4
Merge branch 'master' of https://github.com/lawncegoh/duke
lawncegoh Aug 22, 2019
87c298d
Level-5. Handle Errors
lawncegoh Aug 22, 2019
91c040e
Level-5. Handle Errors
lawncegoh Aug 22, 2019
b0146f9
Level-5. Handle Errors
lawncegoh Aug 22, 2019
5dda65f
Level-5. Handle Errors
lawncegoh Aug 22, 2019
6c0eaf7
Level-6. Delete
lawncegoh Aug 22, 2019
8a58113
Level-5. Handle Errors
lawncegoh Aug 22, 2019
d3cccf1
Level-6. Delete
lawncegoh Aug 22, 2019
4bb4648
Reverse back to level-6
lawncegoh Aug 27, 2019
e964e9f
Level 7. Save
lawncegoh Aug 27, 2019
1dba722
branch-level-8
lawncegoh Aug 27, 2019
b28d390
Merge branch 'branch-Level-8'
lawncegoh Aug 27, 2019
391cd45
A-MoreOOP
lawncegoh Aug 28, 2019
363752c
A-Packages
lawncegoh Aug 28, 2019
b9d91a0
A-JUnit
lawncegoh Aug 28, 2019
c564bb6
Manifest addition
lawncegoh Aug 28, 2019
26975d7
A-JavaDoc
lawncegoh Aug 28, 2019
ec67757
A-CodingStandard
lawncegoh Aug 28, 2019
bd7dd1d
branch-Level-9
lawncegoh Aug 28, 2019
4c842cf
branch-Level-9
lawncegoh Aug 28, 2019
c10bc43
Merge branch 'branch-A-CodingStandard'
lawncegoh Aug 28, 2019
32b18fd
Merge branch 'branch-Level-9'
lawncegoh Aug 28, 2019
9a766b2
Adding gradle support
lawncegoh Sep 2, 2019
68fe08c
A-Gradle
lawncegoh Sep 2, 2019
26d0001
Level-10. GUI
lawncegoh Sep 3, 2019
4aa438f
Level-10. GUI
lawncegoh Sep 3, 2019
5ed5e32
Merge branch 'branch-Level-10'
lawncegoh Sep 3, 2019
c1eb7f2
Edits to GUI
lawncegoh Sep 5, 2019
e8c8738
Updates to GUI
lawncegoh Sep 7, 2019
855e907
A-CodeQuality
lawncegoh Sep 10, 2019
c329c33
A-Assertions
lawncegoh Sep 10, 2019
0ab3dd3
Merge pull request #5 from lawncegoh/A-Assertions
lawncegoh Sep 11, 2019
e2515f4
Merge tag 'A-CodeQuality'
lawncegoh Sep 11, 2019
40fb1ea
Merge branch 'master' of https://github.com/lawncegoh/duke
lawncegoh Sep 11, 2019
d3cd4a9
Updating of GUI
lawncegoh Sep 11, 2019
badbd4e
Updated certain assertions and removed the isExit() method
lawncegoh Sep 17, 2019
8d5db91
Updated representative screenshot
lawncegoh Sep 17, 2019
657f9d9
Delete Ui.png
lawncegoh Sep 17, 2019
5c1da8d
Change of screenshot to add in title at the top
lawncegoh Sep 17, 2019
67eb7c9
Changed profile images and took away irrelevant methods in some classes
lawncegoh Sep 17, 2019
21447af
Merge branch 'master' of https://github.com/lawncegoh/duke
lawncegoh Sep 17, 2019
0600f0c
added C-Tagging
lawncegoh Sep 17, 2019
dbe8517
Update README.md
lawncegoh Sep 17, 2019
814e460
Update README.md
lawncegoh Sep 17, 2019
c613c2e
Added User Guide
lawncegoh Sep 17, 2019
bab5a4f
Update README.md
lawncegoh Sep 17, 2019
10720fd
Minor changes in codestyle
lawncegoh Sep 17, 2019
aadd31b
Set theme jekyll-theme-slate
lawncegoh Sep 17, 2019
086722f
Set theme jekyll-theme-slate
lawncegoh Sep 17, 2019
d638a11
Edits to jar file
lawncegoh Sep 17, 2019
374317d
Update Readme
lawncegoh Sep 17, 2019
cd623e1
Added in Help Command, made some changes to Parser to add in this com…
lawncegoh Sep 17, 2019
2d3c306
Made changes and added comments to make date method
lawncegoh Sep 17, 2019
86bb0f1
Updated dependencies
lawncegoh Sep 17, 2019
076e3c7
update
lawncegoh Sep 18, 2019
1ffbd0d
Merge pull request #8 from lawncegoh/A-Assertions1
lawncegoh Sep 18, 2019
7e58400
Delete Ui.png
lawncegoh Sep 27, 2019
5551226
Add files via upload
lawncegoh Sep 27, 2019
dae78f4
Updates to the GUI
lawncegoh Sep 27, 2019
dd50750
Merge branch 'master' of https://github.com/lawncegoh/duke
lawncegoh Sep 27, 2019
04a862b
Update README.md
lawncegoh Sep 29, 2019
ee20d73
Updated README
lawncegoh Sep 29, 2019
43dd94b
Update README.md
lawncegoh Sep 29, 2019
a42a65d
Merge branch 'master' of https://github.com/lawncegoh/duke
lawncegoh Sep 29, 2019
54a6128
Update README.md
lawncegoh Sep 29, 2019
f57d77e
Set theme jekyll-theme-minimal
lawncegoh Sep 29, 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
4 changes: 4 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
T|1| read book
D|0| return book | June 6th
D|1| return book | 2nd of December 0019, 6:00pm
E|1| return book | 2nd of December 0019, 7:00pm
Binary file added src/main/java/Duke.class
Binary file not shown.
70 changes: 63 additions & 7 deletions src/main/java/Duke.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,66 @@
import duke.command.Command;
import duke.exception.DukeException;
import duke.parser.Parser;
import duke.storage.Storage;
import duke.tasklist.TaskList;
import duke.ui.Ui;

import java.text.ParseException;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

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

public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
} catch (DukeException e) {
ui.showLoadingError();
tasks = new TaskList();
}
}

/**
* Runs the entire logic of the program. showWelcome() displays the duke logo and greets
* the user. isExit boolean ensures that the while loop doesn't end until the user input of
* "bye" is encountered. User's input will be read through the ui and then parsed to give
* a Command object. The specific command will then be executed.
* <p>
* This method has try and catch blocks within to help with catching both DukeException
* and ParseException
*
*/
public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")
Command c = Parser.parse(fullCommand);
c.execute(tasks, ui, storage);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} catch (ParseException e) {
System.out.println(e.getMessage());
} finally {
ui.showLine();
}
}
}

/**
* Runs the main method to load the duke.txt file into the program and then calls the run method
* @param args
* @throws DukeException
lawncegoh marked this conversation as resolved.
Show resolved Hide resolved
* @throws ParseException
lawncegoh marked this conversation as resolved.
Show resolved Hide resolved
*/
public static void main(String[] args) throws DukeException, ParseException{
new Duke("/Users/lawnce/Desktop/duke/data/duke.txt").run();
}
}
3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Duke

Binary file added src/main/java/duke/command/Command.class
Binary file not shown.
14 changes: 14 additions & 0 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package duke.command;

import duke.exception.DukeException;
import duke.storage.Storage;
import duke.tasklist.TaskList;
import duke.ui.Ui;
import java.text.ParseException;

public abstract class Command {

public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException, ParseException;

public abstract boolean isExit();
lawncegoh marked this conversation as resolved.
Show resolved Hide resolved
}
Binary file added src/main/java/duke/command/DeadlineCommand.class
Binary file not shown.
81 changes: 81 additions & 0 deletions src/main/java/duke/command/DeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package duke.command;
Copy link

Choose a reason for hiding this comment

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

Would it be possible to remove the '.class' files? Just curious becuase I didn't package the files.


import duke.exception.DukeException;
import duke.initials.Deadline;
import duke.storage.Storage;
import duke.tasklist.TaskList;
import duke.ui.Ui;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DeadlineCommand extends Command {

public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy HHmm");
lawncegoh marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates new deadline task using a TaskList, Ui and Storage, it will then be added into the taskArrayList that
* was loaded into the TaskList as param.
* @param tasks the TaskList to be used
* @param ui the Ui to be used
* @param storage the Storage to be used
* @throws DukeException
* @throws ParseException if the date is not able to be parsed
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException, ParseException {

int end2 = ui.getRemainingWords().indexOf('/');
lawncegoh marked this conversation as resolved.
Show resolved Hide resolved
if (end2 > 0) {

String description2 = ui.getRemainingWords().substring(1, ui.getRemainingWords().indexOf('/'));
String time2 = ui.getRemainingWords().substring(end2 + 4).trim();
if (time2.isEmpty()) {
throw new DukeException("☹OOPS!!! Wrong format'");
} else {
Deadline k = new Deadline(description2, makeDate(time2));
tasks.add(k);
storage.writeData();
System.out.println("Got it. I've added this task:");
System.out.println(k);
System.out.println("Now you have " + tasks.getTaskArrayList().size() + " tasks in the list.");
Copy link

Choose a reason for hiding this comment

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

If there is only one task, it will print "Now you have 1 tasks in the list". It might be better to add an if-else block for singular task?

ui.showLine();
}
} else {
throw new DukeException("☹OOPS!!! Wrong format");
}
}

/**
* Returns true or false regarding whether this method will end the while loop in the duke method run()
* @return false or true
*/
public boolean isExit() {
return false;
}

public String makeDate(String input) throws ParseException {
Copy link

Choose a reason for hiding this comment

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

Good catch for invalid date. I forgot :(

String ordinalIndicator;
Date date = DATE_FORMAT.parse(input);
String day = new SimpleDateFormat("dd").format(date);
String month = new SimpleDateFormat("MMMMMMMMMMM").format(date);
String year = new SimpleDateFormat("yyyy").format(date);
String time = new SimpleDateFormat("h:mma").format(date).toLowerCase();

int int_day = Integer.parseInt(day);
if (int_day >= 11 && int_day <= 13) {
lawncegoh marked this conversation as resolved.
Show resolved Hide resolved
ordinalIndicator = "th";
} else if (int_day % 10 == 1) {
ordinalIndicator = "st";
} else if (int_day % 10 == 2) {
ordinalIndicator = "nd";
} else if (int_day % 10 == 3) {
ordinalIndicator = "rd";
} else {
ordinalIndicator = "th";
}

String outputDate = int_day + ordinalIndicator + " of " + month + " " + year + ", " + time;
return outputDate;
}
}
Binary file added src/main/java/duke/command/DeleteCommand.class
Binary file not shown.
39 changes: 39 additions & 0 deletions src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package duke.command;

import duke.exception.DukeException;
import duke.storage.Storage;
import duke.tasklist.TaskList;
import duke.ui.Ui;

public class DeleteCommand extends Command {

/**
* Creates new deadline task using a TaskList, Ui and Storage, it will then be added into the taskArrayList that
* was loaded into the TaskList as param.
* @param tasks the TaskList to be used
* @param ui the Ui to be used
* @param storage the Storage to be used
* @throws DukeException
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
if (ui.getRemainingWords().isEmpty()) {
throw new DukeException("☹OOPS!!! Wrong format");
}
int position = Integer.parseInt(ui.getRemainingWords().trim());
System.out.println("Noted. I've removed this task.");
System.out.println(tasks.getTaskArrayList().get(position-1));
tasks.delete(position-1);
storage.writeData();
System.out.println("Now you have " + tasks.getTaskArrayList().size() + " tasks in the list");
}

/**
* Returns true or false regarding whether this method will end the while loop in the duke method run()
Copy link

Choose a reason for hiding this comment

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

Perhaps you can rephrase the descriptions for isExit() and its return value as they seem a bit repetitive now...?

* @return false or true
*/
@Override
public boolean isExit() {
return false;
}
}
Binary file added src/main/java/duke/command/DoneCommand.class
Binary file not shown.
35 changes: 35 additions & 0 deletions src/main/java/duke/command/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package duke.command;

import duke.storage.Storage;
import duke.tasklist.TaskList;
import duke.ui.Ui;

public class DoneCommand extends Command {

int index;

/**
* Creates new deadline task using a TaskList, Ui and Storage, it will then be added into the taskArrayList that
* was loaded into the TaskList as param.
* @param tasks the TaskList to be used
* @param ui the Ui to be used
* @param storage the Storage to be used
*/
public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.showLine();
index = Integer.parseInt(ui.getRemainingWords().trim());
tasks.getTaskArrayList().get(index - 1).markAsDone();
storage.writeData();
System.out.println("Nice! I've marked this task as done:");
System.out.println(tasks.getTaskArrayList().get(index - 1));
ui.showLine();
}

/**
* Returns true or false regarding whether this method will end the while loop in the duke method run()
* @return false or true
*/
public boolean isExit() {
return false;
}
}
Binary file added src/main/java/duke/command/EventCommand.class
Binary file not shown.
82 changes: 82 additions & 0 deletions src/main/java/duke/command/EventCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package duke.command;

import duke.exception.DukeException;
import duke.initials.Event;
import duke.storage.Storage;
import duke.tasklist.TaskList;
import duke.ui.Ui;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class EventCommand extends Command {

public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy HHmm");

/**
* Creates new deadline task using a TaskList, Ui and Storage, it will then be added into the taskArrayList that
* was loaded into the TaskList as param.
* @param tasks the TaskList to be used
* @param ui the Ui to be used
* @param storage the Storage to be used
* @throws DukeException
* @throws ParseException if the date is not able to be parsed
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException, ParseException{
ui.showLine();
int end = ui.getRemainingWords().indexOf('/');
if (end > 0) {
String description = ui.getRemainingWords().substring(1, ui.getRemainingWords().indexOf('/'));
String time = ui.getRemainingWords().substring(end + 4).trim();
if (time.isEmpty()) {
throw new DukeException("☹OOPS!!! Wrong format'");
} else {
Event m = new Event(description, makeDate(time));
tasks.add(m);
storage.writeData();

System.out.println("Got it. I've added this task:");
System.out.println(m);
System.out.println("Now you have " + tasks.getTaskArrayList().size() + " tasks in the list.");
ui.showLine();
}
} else {
throw new DukeException("☹OOPS!!! Wrong format'");
}
}

/**
* Returns true or false regarding whether this method will end the while loop in the duke method run()
* @return false or true
*/
public boolean isExit() {
return false;
}

public String makeDate(String input) throws ParseException {
String ordinalIndicator;
Date date = DATE_FORMAT.parse(input);
String day = new SimpleDateFormat("dd").format(date);
String month = new SimpleDateFormat("MMMMMMMMMMM").format(date);
String year = new SimpleDateFormat("yyyy").format(date);
String time = new SimpleDateFormat("h:mma").format(date).toLowerCase();

int int_day = Integer.parseInt(day);

if (int_day >= 11 && int_day <= 13) {
ordinalIndicator = "th";
} else if (int_day % 10 == 1) {
ordinalIndicator = "st";
} else if (int_day % 10 == 2) {
ordinalIndicator = "nd";
} else if (int_day % 10 == 3) {
ordinalIndicator = "rd";
} else {
ordinalIndicator = "th";
}

String outputDate = int_day + ordinalIndicator + " of " + month + " " + year + ", " + time;
return outputDate;
}
}
Binary file added src/main/java/duke/command/ExitCommand.class
Binary file not shown.
31 changes: 31 additions & 0 deletions src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package duke.command;

import duke.storage.Storage;
import duke.tasklist.TaskList;
import duke.ui.Ui;

public class ExitCommand extends Command {

/**
* Creates new deadline task using a TaskList, Ui and Storage, it will then be added into the taskArrayList that
* was loaded into the TaskList as param.
* @param tasks the TaskList to be used
* @param ui the Ui to be used
* @param storage the Storage to be used
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.showLine();
System.out.println("Bye. Hope to see you again soon!");
ui.showLine();
}

/**
* Returns true or false regarding whether this method will end the while loop in the duke method run()
* @return false or true
*/
@Override
public boolean isExit() {
return true;
}
}
Binary file added src/main/java/duke/command/FindCommand.class
Binary file not shown.
Loading