Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
812d612
replace Duke file with Tommi file
ryan-txn Aug 22, 2024
5f645dc
Revert "replace Duke file with Tommi file"
ryan-txn Aug 29, 2024
398cd22
Reapply "replace Duke file with Tommi file"
ryan-txn Aug 29, 2024
c034cfe
Add repeating strings and detecting "bye" string
ryan-txn Aug 29, 2024
e40ebef
Add list of tasks
ryan-txn Aug 29, 2024
ac8dc0f
Add checklist
ryan-txn Aug 29, 2024
629ee35
Fix coding standards
ryan-txn Aug 29, 2024
2e66a92
Employ OOP Princples
ryan-txn Sep 6, 2024
24f24e1
Include ToDo, Deadline and Event Task subclasses
ryan-txn Sep 6, 2024
85d21eb
Handle exceptions
ryan-txn Sep 12, 2024
baaa892
Revert "Handle exceptions"
ryan-txn Sep 12, 2024
b541ecf
Reapply "Handle exceptions"
ryan-txn Sep 12, 2024
3f8a8c4
Revert "Handle exceptions"
ryan-txn Sep 12, 2024
86955e5
Merge branch 'master' into branch-Level-5
ryan-txn Sep 12, 2024
f6e1caf
Merge branch 'branch-Level-5'
ryan-txn Sep 12, 2024
0026848
Redo exception handling, Package code
ryan-txn Sep 12, 2024
792321a
add commit for branch
ryan-txn Sep 19, 2024
1deffba
Revert "add commit for branch"
ryan-txn Sep 19, 2024
320ae65
Use ArrayList to replace Array and Add delete task function
ryan-txn Sep 20, 2024
6fc8417
Merge branch 'branch-Level-6'
ryan-txn Sep 20, 2024
13228d4
Add save and load functions
ryan-txn Sep 24, 2024
4f06d99
Merge branch 'branch-Level-7'
ryan-txn Sep 24, 2024
125ed9b
Rename classes and add Task package
ryan-txn Oct 6, 2024
ca9594a
Add Search function
ryan-txn Oct 10, 2024
f7f975c
Improve readability and Shift readInputStrings method from Ui to Parser
ryan-txn Oct 10, 2024
5a0c049
Move all print functions to Ui class
ryan-txn Oct 10, 2024
0c922cd
Improve OOP
ryan-txn Oct 10, 2024
7abb9b4
Merge pull request #1 from ryan-txn/branch-Level-9
ryan-txn Oct 10, 2024
0e51847
JavaDoc comments
ryan-txn Oct 10, 2024
2af8a9f
Merge pull request #2 from ryan-txn/heads/A-JavaDoc
ryan-txn Oct 10, 2024
4cdbe9d
Update User Guide
ryan-txn Oct 10, 2024
eb37c84
Merge pull request #3 from ryan-txn/heads/A-UserGuide
ryan-txn Oct 10, 2024
2cd120d
Save file bug fix
ryan-txn Oct 13, 2024
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
18 changes: 18 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Deadline extends Task{

protected String by;

public Deadline(boolean isDone, String taskName, String by) {
super(isDone, taskName);
this.by = by;
}

public Deadline updateIsDone(boolean newIsDone) {
return new Deadline(newIsDone, this.taskName, this.by);
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
Comment on lines +1 to +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like the immutability of the updateIsDone method and the clear toString representation. A small suggestion would be to validate the by field if it's supposed to follow a specific format (like a date or time). You might also want to add a method to update the deadline (by) in the future, just like you did for isDone. Otherwise, everything looks really well-structured!

10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Event extends Task{

protected String from;
protected String to;


public Event(boolean isDone, String taskName, String from, String to) {
super(isDone, taskName);
this.from = from;
this.to = to;
}

public Event updateIsDone(boolean newIsDone) {
return new Event(newIsDone, this.taskName, this.from, this.to);
}

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + this.from + " to " + this.to + ")";
}
}
40 changes: 40 additions & 0 deletions src/main/java/InputHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
public class InputHandler {

public static void processInputCases(String input) {
if (input.equals("list")) {
TaskList.listTasks();
return;
}

String[] words = input.split(" ");
int taskIndex;

switch (words[0]) {
case "mark":
taskIndex = Integer.parseInt(words[1]) - 1;
TaskList.markTask(taskIndex);
break;
case "unmark":
taskIndex = Integer.parseInt(input.substring(7)) - 1;
TaskList.unmarkTask(taskIndex);
break;
case "todo":
TaskList.addTask(new ToDo(false, input.substring(5)));
break;
case "deadline":
String[] deadlineParts = input.substring(9).split("/by", 2);
TaskList.addTask(new Deadline(false, deadlineParts[0], deadlineParts[1]));
break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like the clear logic, use of switch and how compact everything is! One thing to consider is adding more error handling, especially around Integer.parseInt() and array indexing, to prevent crashes on invalid inputs. It might also be worth refactoring the splitting of strings into helper methods for better readability .

case "event":
String[] eventParts = input.split("/from", 2);

// Split the remaining part by /to
String[] timeParts = eventParts[1].split("/to", 2);

TaskList.addTask(new Event(false, eventParts[0], timeParts[0], timeParts[1]));
break;
default:
TaskList.addTask(new Task(false, input));
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Task {

protected final boolean isDone;
protected final String taskName;

public Task(boolean isDone, String taskName) {
this.isDone = isDone;
this.taskName = taskName;
}

public Task updateIsDone(boolean newIsDone) {
return new Task(newIsDone, this.taskName);
}

@Override
public String toString() {
return ("[" + (isDone ? "X" : " ") + "] " + taskName);
}
}
46 changes: 46 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
public class TaskList {

private static final int MAX_TASKS = 100;

private static final Task[] tasks = new Task[MAX_TASKS]; // Array to store tasks
private static int tasksCount = 0; // Counter to keep track of the number of tasks

public static void listTasks() {
Tommi.printLine();
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < tasksCount; i++) {
System.out.println((i + 1) + ". " + tasks[i]);
}
Tommi.printLine();
}

public static void addTask(Task task) {
tasks[tasksCount] = task;
tasksCount++;
Tommi.printLine();
System.out.println("Sure. I've added the task: " + System.lineSeparator()
+ task + System.lineSeparator()
+ "There are now " + tasksCount + " tasks in the list.");
Tommi.printLine();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The class is well structured, and the methods are concise and really easy to understand 😄. Would you want to switch a dynamic data structure later down the track (i.e. ArrayList), to give you some scalability? It might also be good to add boundary checks for adding tasks to ensure it doesn’t exceed MAX_TASKS. Overall, great foundation!

}

public static void markTask(int index) {
if (index >= 0 && index < tasksCount) {
Tommi.printLine();
System.out.println("Awesomesauce! I've marked this task as done:");
tasks[index] = tasks[index].updateIsDone(true);
System.out.println(tasks[index]);
Tommi.printLine();
}
}

public static void unmarkTask(int index) {
if (index >= 0 && index < tasksCount) {
Tommi.printLine();
System.out.println("OK, I've marked this task as undone:");
tasks[index] = tasks[index].updateIsDone(false);
System.out.println(tasks[index]);
Tommi.printLine();
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class ToDo extends Task{

public ToDo(boolean isDone, String taskName) {
super(isDone, taskName);
}

public ToDo updateIsDone(boolean newIsDone) {
return new ToDo(newIsDone, this.taskName);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
44 changes: 44 additions & 0 deletions src/main/java/Tommi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.util.Scanner;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can consider adding comments to help with readability


public class Tommi {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

printIntroMessage();
readInputStrings(scanner);
printExitMessage();
}

private static void readInputStrings(Scanner scanner) {
String input = scanner.nextLine();
while (!input.equals("bye")) {
InputHandler.processInputCases(input);
input = scanner.nextLine();
}
}

private static void printIntroMessage() {
String intro = """
______ \s
/_ __/__ __ _ __ _ (_)
/ / / _ \\/ ' \\/ ' \\/ /\s
/_/ \\___/_/_/_/_/_/_/_/ \s
____________________________________________________________
Hello! I'm Tommi!
What can I do for you?
____________________________________________________________
""";
System.out.println(intro);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I appreciate the effort gone to customise your logo, and abstract it to a function for later use!


private static void printExitMessage() {
printLine();
System.out.println("Bye. Hope to see you again soon!");
printLine();
}

public static void printLine() {
System.out.println("____________________________________________________________");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using ( "_*30" ) instead

}
}