-
Notifications
You must be signed in to change notification settings - Fork 76
imaginarys96 iP #73
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
base: master
Are you sure you want to change the base?
imaginarys96 iP #73
Changes from 6 commits
08758df
70db08d
f199592
74cd269
89fbf7b
c78ca99
fc69e5c
725a683
7f288f7
6d91851
45634a7
05dfeaf
c6f11a2
0321771
5526242
a608f54
5e2946d
46504a4
5b89da7
c33523b
2026fdf
0465ace
3c63edf
8b4c583
0838b6a
1e16cf3
ba940d1
888536f
5cc3861
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Chatbot { | ||
| public static void main(String[] args) { | ||
| Task[] tasks = new Task[100]; | ||
| int numOfTasks = 0; | ||
|
|
||
| String greetingMsg = "____________________________________________________________\n" + | ||
| " Hello! I'm Chatbot\n" + | ||
| " What can I do for you?\n" + | ||
| "____________________________________________________________\n"; | ||
| String byeMsg = "____________________________________________________________\n" + | ||
| " Bye. Hope to see you again soon!\n" + | ||
| "____________________________________________________________\n"; | ||
| System.out.println(greetingMsg); | ||
|
|
||
|
|
||
| Scanner in = new Scanner(System.in); | ||
| String input = in.nextLine(); | ||
| while(!input.equals("bye")) { | ||
| if (input.equals("list")) { | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Here are the tasks in your list:"); | ||
| for (int i = 0; i < numOfTasks; i++) { | ||
| System.out.println(" " + (i + 1) + ".[" + tasks[i].getTypeIcon() + "][" + tasks[i].getStatusIcon() + "] " + tasks[i].getDescription()); | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (input.startsWith("mark ")) { | ||
| String number = input.replace("mark ", "").trim(); | ||
| int markTaskNo = Integer.parseInt(number); | ||
|
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. noun should not be named with a verb in it, recommend to combine with previous line and use taskNumber as previously mentioned |
||
| if (markTaskNo > 0) { | ||
| tasks[markTaskNo - 1].markAsDone(); | ||
|
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. using -1 magical number, would be good to define what the -1 means |
||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Nice! I've marked this task as done:"); | ||
| System.out.println(" [" + tasks[markTaskNo - 1].getStatusIcon() + "] " + tasks[markTaskNo - 1].getDescription()); | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (input.startsWith("unmark ")) { | ||
| String number = input.replace("unmark ", "").trim(); | ||
| int unmarkTaskNo = Integer.parseInt(number); | ||
|
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. variable name can be mistaken as an action, recommend to use unmarkedTaskNo |
||
| if (unmarkTaskNo > 0) { | ||
| tasks[unmarkTaskNo - 1].markAsUndone(); | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" OK, I've marked this task as not done yet:"); | ||
| System.out.println(" [" + tasks[unmarkTaskNo - 1].getStatusIcon() + "] " + tasks[unmarkTaskNo - 1].getDescription()); | ||
| System.out.println("____________________________________________________________"); | ||
| } else if ( input.startsWith("todo") ) { | ||
|
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. unnecessary spaces for start and ends of brackets |
||
|
|
||
| String msg = input.replace("todo ", "").trim(); | ||
| msg = msg.replace("deadline", ""); | ||
| msg = msg.replace("event", ""); | ||
|
|
||
| Task task = new Task(input, "T"); | ||
| tasks[numOfTasks] = task; | ||
| numOfTasks++; | ||
|
|
||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Got it. I've added this task:"); | ||
| System.out.println(" [" + task.getTypeIcon() + "][" + task.getStatusIcon() + "] " + task.getDescription()); | ||
| System.out.println(" Now you have " + String.valueOf(numOfTasks) + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } else if ( input.startsWith("deadline") ) { | ||
| String msg = input.replace("deadline", ""); | ||
|
|
||
| Task task = new Task(input, "D"); | ||
| tasks[numOfTasks] = task; | ||
| numOfTasks++; | ||
|
|
||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Got it. I've added this task:"); | ||
| System.out.println(" [" + task.getTypeIcon() + "][" + task.getStatusIcon() + "] " + task.getDescription()); | ||
| System.out.println(" Now you have " + String.valueOf(numOfTasks) + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } else if ( input.startsWith("event") ) { | ||
| String msg = input.replace("event", ""); | ||
|
|
||
| Task task = new Task(input, "E"); | ||
| tasks[numOfTasks] = task; | ||
| numOfTasks++; | ||
|
|
||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Got it. I've added this task:"); | ||
| System.out.println(" [" + task.getTypeIcon() + "][" + task.getStatusIcon() + "] " + task.getDescription()); | ||
| System.out.println(" Now you have " + String.valueOf(numOfTasks) + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } else { | ||
| // if not bye, list, mark, then the command by default is add | ||
| tasks[numOfTasks] = new Task(input, ""); | ||
| numOfTasks++; | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("added: " + input); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
|
|
||
| input = in.nextLine(); | ||
| } | ||
| System.out.println(byeMsg); | ||
|
|
||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
| protected String type; | ||
|
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. type is ambiguous, can be mistaken as a verb, recommend to use taskType |
||
| public Task(String description, String type) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| this.type = type; | ||
| } | ||
| public String getDescription() { | ||
| return this.description; | ||
| } | ||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X | ||
| } | ||
| public void markAsDone() { | ||
| this.isDone = true; | ||
| } | ||
| public void markAsUndone() { | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getTypeIcon() { return type; } | ||
|
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. curly bracket should start on a newline |
||
|
|
||
| } | ||
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.
number is ambiguous, recommend to use taskNumber