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

[randallnhr] iP #389

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
d931af6
Level-1
randallnhr Jan 16, 2023
34904a0
Level-1
randallnhr Jan 16, 2023
4e12dad
Level-2
randallnhr Jan 16, 2023
510ffff
Level-3
randallnhr Jan 18, 2023
927000e
Level-4
randallnhr Jan 19, 2023
7315848
A-TextUiTesting
randallnhr Jan 20, 2023
149e1d0
Level-5
randallnhr Jan 20, 2023
357e5f7
Level-6
randallnhr Jan 20, 2023
c2c6903
Level-7
randallnhr Feb 3, 2023
231ec2e
Level-8
randallnhr Feb 4, 2023
4614698
updated input and expected txt files
randallnhr Feb 4, 2023
dbb7cbf
Merge branch 'branch-Level-8'
randallnhr Feb 4, 2023
df38bca
Merge Level-8 to master
randallnhr Feb 4, 2023
5c0e7b1
A-MoreOOP
randallnhr Feb 4, 2023
674f297
A-Packages
randallnhr Feb 5, 2023
c894cbf
Merge remote-tracking branch 'origin/add-gradle-support'
randallnhr Feb 5, 2023
2e673f7
A-Gradle
randallnhr Feb 5, 2023
359765a
A-JUnit
randallnhr Feb 5, 2023
224fa30
Add increment A-JavaDoc
randallnhr Feb 5, 2023
24d5209
Remove redundant codes and correct layout of code
randallnhr Feb 5, 2023
74266a2
Add increment Level-9
randallnhr Feb 5, 2023
56f1dc5
Merge branch 'branch-A-CodingStandard'
randallnhr Feb 5, 2023
25c6740
Merge branch 'branch-Level-9'
randallnhr Feb 5, 2023
1318085
Add GUI
randallnhr Feb 11, 2023
31a8483
Add GUI
randallnhr Feb 12, 2023
c0d137a
Merge branch 'branch-Level-10'
randallnhr Feb 12, 2023
caacaec
Add assertions
randallnhr Feb 12, 2023
0af8473
Merge pull request #2 from randallnhr/branch-A-Assertions
randallnhr Feb 12, 2023
47ec878
Improve CodeQuality
randallnhr Feb 12, 2023
8794559
Fix error in Parser
randallnhr Feb 12, 2023
c21cf25
Merge pull request #3 from randallnhr/branch-A-CodeQuality
randallnhr Feb 12, 2023
8539e7e
Add reschedule functionality
randallnhr Feb 14, 2023
d962643
Merge branch 'branch-BCD-Extension'
randallnhr Feb 14, 2023
47632b4
Improve GUI
randallnhr Feb 16, 2023
0f35873
Add personality
randallnhr Feb 16, 2023
1c91d33
Add personality
randallnhr Feb 16, 2023
919e432
Edit delete and error message
randallnhr Feb 16, 2023
9a5d484
Add Ui.png
randallnhr Feb 16, 2023
a70e173
Edit README.md
randallnhr Feb 17, 2023
0c185b1
Edit README.md
randallnhr Feb 17, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ bin/

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT

*.class
23 changes: 23 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.time.LocalDate;

class Deadline extends Task {
private LocalDate deadline;
public Deadline(String name, String start) {
super(name);
this.deadline = LocalDate.parse(start);
}

@Override
public String getFileDesc() {
return this.isDone
? "D|1|" + this.name + "|" + convertFileDate(this.deadline)
: "D|0|" + this.name + "|" + convertFileDate(this.deadline);
}

@Override
public String toString() {
return this.isDone
? "[D][X] " + this.name + " (by: " + getDate(this.deadline) + ")"
: "[D][ ] " + this.name + " (by: " + getDate(this.deadline) + ")";
}
}

Choose a reason for hiding this comment

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

Perhaps, instead of leaving the isDone logic in this toString() function, you could leave it in the Task class instead so that you dont have to retype so much code if you need to create a new Task type in the future.

154 changes: 147 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,150 @@
import java.io.IOException;

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

private static final String SAVE_PATH = "./taskList.txt";
private Storage storage;
private TaskList taskList;
private Ui ui = new Ui();
private Parser parser = new Parser();

public Duke() {
try {
this.storage = new Storage(SAVE_PATH);
this.taskList = storage.loadData();
} catch (DukeException e) {
System.out.println(e.getMessage());
}
}

public void run() {
try {
ui.start();
String[] input = ui.readLine();
while (!input[0].equals("bye")) {
ui.displayLine();
parser.readInput(input, taskList);
ui.displayLine();
input = ui.readLine();
}
ui.goodbye();
storage.storeData(this.taskList.getTasks());
} catch (DukeException e) {
System.out.println(e.getMessage());
}
}

public static void main(String[] args) throws IOException, DukeException {
new Duke().run();
}
}
// System.out.println("Hello! I'm Duke\n" +
// "What can I do for you?");

// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// try {
// ArrayList<Task> lst = loadData(SAVE_PATH);
// int count = 0 + lst.size();
// String[] word = br.readLine().strip().split(" ",2);

// while (!word[0].equals("bye")) {
// try {
// if (word[0].equals("list")) {
// int curr = 1;
// Iterator<Task> iter = lst.iterator();
// while (iter.hasNext()) {
// System.out.println(curr + " " + iter.next());
// curr++;
// }
// word = br.readLine().strip().split(" ",2);
// } else if (word[0].equals("mark")) {
// if (word.length == 1) {
// throw new DukeException("Mark needs a number.");
// }
// if (Integer.parseInt(word[1]) > count) {
// throw new DukeException("Invalid task.");
// }
// Task t = lst.get(Integer.parseInt(word[1]) - 1);
// t.isDone = true;
// System.out.println("Task has been marked as done:\n " + t);
// word = br.readLine().split(" ",2);
// } else if (word[0].equals("unmark")) {
// if (word.length == 1) {
// throw new DukeException("Unmark needs a number.");
// }
// if (Integer.parseInt(word[1]) > count) {
// throw new DukeException("Invalid task.");
// }
// Task t = lst.get(Integer.parseInt(word[1]) - 1);
// t.isDone = false;
// System.out.println("Task has been marked as not done:\n " + t);
// word = br.readLine().split(" ",2);
// } else if (word[0].equals("todo")) {
// if (word.length == 1) {
// throw new DukeException("todo needs a description");
// }
// Task t = new Todo(word[1].strip());
// lst.add(t);
// count++;
// System.out.println("Added new todo:\n " + t + "\nNumber of tasks: " + count);
// word = br.readLine().strip().split(" ",2);
// } else if (word[0].equals("deadline")) {
// if (word.length == 1 || !word[1].contains("/by")) {
// throw new DukeException("Deadline needs a /by.");
// }
// String[] tempWord = word[1].strip().split("/by ");
// if (tempWord.length == 1) {
// throw new DukeException("/by needs a date/time.");
// }
// try {
// Task t = new Deadline(tempWord[0].strip(), tempWord[1].strip());
// lst.add(t);
// count++;
// System.out.println("Added new deadline:\n " + t + "\nNumber of tasks: " + count);
// word = br.readLine().strip().split(" ",2);
// } catch (DateTimeParseException e) {
// throw new DukeException("Date after /by needs to be in format yyyy-mm-dd");
// }
// } else if (word[0].equals("event")) {
// if (word.length == 1 || !word[1].contains("/from") || !word[1].contains("/to") ) {
// throw new DukeException("Event needs a /from and /to.");
// }
// String[] tempWord = word[1].split("/");
// String[] from = tempWord[1].split(" ",2);
// String[] to = tempWord[2].split(" ",2);
// if (from.length == 1 || to.length == 1) {
// throw new DukeException("/from and /to needs a date/time.");
// }
// try {
// Task t = new Event(tempWord[0].strip(), from[1].strip(), to[1].strip());
// lst.add(t);
// count++;
// System.out.println("Added new event:\n " + t + "\nNumber of tasks: " + count);
// word = br.readLine().strip().split(" ",2);
// } catch (DateTimeParseException e) {
// throw new DukeException("Date after /from and /to needs to be in format yyyy-mm-dd");
// }
// } else if (word[0].equals("delete")) {
// if (word.length == 1) {
// throw new DukeException("Delete needs a number.");
// }
// if (Integer.parseInt(word[1]) > count) {
// throw new DukeException("Invalid task.");
// }
// Task t = lst.remove(Integer.parseInt(word[1]) - 1);
// count--;
// System.out.println("Deleted task:\n " + t + "\nNumber of tasks: " + count);
// word = br.readLine().strip().split(" ",2);
// } else {
// throw new DukeException("Sorry I do not understand the command");
// }
// } catch (DukeException e) {
// System.out.println(e.getMessage());
// word = br.readLine().strip().split(" ",2);
// }
// }
// storeData(lst);
// System.out.println("Duke: Goodbye");
// } catch (IOException e) {
// System.out.println(e.getMessage());
// }

Choose a reason for hiding this comment

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

I suggest you to just delete all these unnecessary commented code. That is mainly the point of a version control system like git which is to undo any changes that you might not like in the future. Commenting them out and leaving them in code makes your code unnecssarily long and confusing.

5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class DukeException extends Exception{
public DukeException(String m) {
super(m);
}
}
28 changes: 28 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.time.LocalDate;

class Event extends Task {
private LocalDate from;
private LocalDate to;
public Event(String name, String start, String end) throws DukeException {
super(name);
this.from = LocalDate.parse(start);
this.to = LocalDate.parse(end);
if (this.from.isAfter(this.to)) {
throw new DukeException("/to date is before /from date");
}
}

@Override
public String getFileDesc() {
return this.isDone
? "E|1|" + this.name + "|" + convertFileDate(this.from) + "|" + convertFileDate(this.to)
: "E|0|" + this.name + "|" + convertFileDate(this.from) + "|" + convertFileDate(this.to);
}

@Override
public String toString() {
return this.isDone
? "[E][X] " + this.name + " (from: " + getDate(this.from) + " to: " + getDate(this.to) + ")"
: "[E][ ] " + this.name + " (from: " + getDate(this.from) + " to: " + getDate(this.to) + ")";
}
}
109 changes: 109 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import java.time.format.DateTimeParseException;

public class Parser {
public Parser() {};

public void readInput(String[] input, TaskList taskList) throws DukeException {
switch (input[0]) {
case "list":
taskList.list();
break;
case "mark":
mark(input, taskList);
break;
case "unmark":
unmark(input, taskList);
break;
case "todo":
todo(input, taskList);
break;
case "deadline":
deadline(input, taskList);
break;
case "event":
event(input, taskList);
break;
case "delete":
delete(input, taskList);
break;
default:
throw new DukeException("Sorry I do not understand the command");
}
}

public void mark(String[] input, TaskList taskList) throws DukeException {
if (input.length == 1) {
throw new DukeException("Mark needs a number.");
}
if (Integer.parseInt(input[1]) > taskList.size()) {
throw new DukeException("Invalid task.");
}
taskList.markTask(Integer.parseInt(input[1]) - 1);
}

public void unmark(String[] input, TaskList taskList) throws DukeException {
if (input.length == 1) {
throw new DukeException("Unmark needs a number.");
}
if (Integer.parseInt(input[1]) > taskList.size()) {
throw new DukeException("Invalid task.");
}
taskList.unmarkTask(Integer.parseInt(input[1]) - 1);
}

public void todo(String[] input, TaskList taskList) throws DukeException {
if (input.length == 1) {
throw new DukeException("todo needs a description");
}
Task t = new Todo(input[1].strip());
taskList.addTask(t);
System.out.println("Added new todo:\n " + t + "\nNumber of tasks: " + taskList.size());
}

public void deadline(String[] input, TaskList taskList) throws DukeException {
if (input.length == 1 || !input[1].contains("/by")) {
throw new DukeException("Deadline needs a /by.");
}
String[] tempInput = input[1].strip().split("/by ");
if (tempInput.length == 1) {
throw new DukeException("/by needs a date/time.");
}
try {
Task t = new Deadline(tempInput[0].strip(), tempInput[1].strip());
taskList.addTask(t);
System.out.println("Added new deadline:\n " + t + "\nNumber of tasks: " + taskList.size());
} catch (DateTimeParseException e) {
throw new DukeException("Date after /by needs to be in format yyyy-mm-dd");
}
}

public void event(String[] input, TaskList taskList) throws DukeException {
if (input.length == 1 || !input[1].contains("/from") || !input[1].contains("/to") ) {
throw new DukeException("Event needs a /from and /to.");
}
String[] tempInput = input[1].split("/");
String[] from = tempInput[1].split(" ",2);
String[] to = tempInput[2].split(" ",2);
if (from.length == 1 || to.length == 1) {
throw new DukeException("/from and /to needs a date/time.");
}
try {
Task t = new Event(tempInput[0].strip(), from[1].strip(), to[1].strip());
taskList.addTask(t);
System.out.println("Added new event:\n " + t + "\nNumber of tasks: " + taskList.size());
} catch (DateTimeParseException e) {
throw new DukeException("Date after /from and /to needs to be in format yyyy-mm-dd");
}
}

public void delete(String[] input, TaskList taskList) throws DukeException {
if (input.length == 1) {
throw new DukeException("Delete needs a number.");
}
int index = Integer.parseInt(input[1]);
if (index > taskList.size()) {
throw new DukeException("Invalid task.");
}
taskList.deleteTask(index - 1);
}
}
Loading