-
Notifications
You must be signed in to change notification settings - Fork 116
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
base: master
Are you sure you want to change the base?
[Ryan Tan] iP #103
Changes from 7 commits
812d612
5f645dc
398cd22
c034cfe
e40ebef
ac8dc0f
629ee35
2e66a92
24f24e1
85d21eb
baaa892
b541ecf
3f8a8c4
86955e5
f6e1caf
0026848
792321a
1deffba
320ae65
6fc8417
13228d4
4f06d99
125ed9b
ca9594a
f7f975c
5a0c049
0c922cd
7abb9b4
0e51847
2af8a9f
4cdbe9d
eb37c84
2cd120d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import java.util.Scanner; | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use a Class to represent all instances of tasks? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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("____________________________________________________________"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using ( "_*30" ) instead |
||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
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 can consider adding comments to help with readability