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

[Ryan Tan] iP #103

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

96 changes: 96 additions & 0 deletions src/main/java/Tommi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import java.util.Scanner;
Copy link

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 {
private static final int MAX_TASKS = 100;
private static final String[] tasks = new String[MAX_TASKS]; // Array to store tasks
private static final boolean[] isCompleted = new boolean[MAX_TASKS]; // Array to store task completion status
private static int taskCount = 0; // Counter to keep track of the number of tasks
Copy link

Choose a reason for hiding this comment

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

Why not use a Class to represent all instances of tasks?

Copy link

Choose a reason for hiding this comment

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

I concur


public static void main(String[] args) {
printIntroMessage();

Scanner scanner = new Scanner(System.in);
String input;

while (true) {
Copy link

Choose a reason for hiding this comment

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

Maybe consider using a variable instead for readability

input = scanner.nextLine(); // Read user input

if (input.equals("bye")) {
printExitMessage();
break; // Exit the loop
} else if (input.equals("list")) {
listTasks();
} else if (input.startsWith("mark ")) {
int taskIndex = Integer.parseInt(input.substring(5)) - 1;
markTask(taskIndex);
} else if (input.startsWith("unmark ")) {
int taskIndex = Integer.parseInt(input.substring(7)) - 1;
unmarkTask(taskIndex);
Copy link

Choose a reason for hiding this comment

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

Consider not having multiple levels of abstraction in a single code fragment

} else {
addTask(input);
}

Choose a reason for hiding this comment

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

Code would be much neater with a switch-case structure instead of if-else.

}
}

private static void printIntroMessage() {
String intro =
" ______ \n"
+ "/_ __/__ __ _ __ _ (_)\n"
+ " / / / _ \\/ ' \\/ ' \\/ / \n"
+ "/_/ \\___/_/_/_/_/_/_/_/ \n"
+ "____________________________________________________________\n"
+ "Hello! I'm Tommi!\n"
+ "What can I do for you?\n"
+ "____________________________________________________________\n";

Choose a reason for hiding this comment

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

Indentation for wrapped lines should be 8 spaces (i.e. twice the normal indentation of 4 spaces) more than the parent line.

Copy link

Choose a reason for hiding this comment

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

You can consider using 8 spaces to split up your line as stated in the coding standard

System.out.println(intro);
}

private static void addTask(String task) {
tasks[taskCount] = task;
isCompleted[taskCount] = false;
taskCount++;
printLine();
System.out.println("added: " + task);
printLine();
}

private static void listTasks() {
printLine();
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < taskCount; i++) {
String status = isCompleted[i] ? "[X]" : "[ ]";
System.out.println((i + 1) + "." + status + " " + tasks[i]);
}
printLine();
}

private static void markTask(int index) {
if (index >= 0 && index < taskCount) {
isCompleted[index] = true;
printLine();
System.out.println("Awesomesauce! I've marked this task as done:");
Copy link

Choose a reason for hiding this comment

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

I like the personality added to the chatbot

System.out.println(" [X] " + tasks[index]);
printLine();
}
Copy link

Choose a reason for hiding this comment

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

Consider including error handling

}

private static void unmarkTask(int index) {
if (index >= 0 && index < taskCount) {
isCompleted[index] = false;
printLine();
System.out.println("OK, I've marked this task as undone:");
System.out.println(" [ ] " + tasks[index]);
printLine();
}
}

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

private static void printLine() {
System.out.println("____________________________________________________________");
Copy link

Choose a reason for hiding this comment

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

Consider using ( "_*30" ) instead

}
}

Choose a reason for hiding this comment

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

The code is good overall. It avoids long methods, deep nesting, complicated expressions and magic numbers. The code is well structured and easily understood.