-
Notifications
You must be signed in to change notification settings - Fork 200
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
[waiter-palypoo] ip #193
base: master
Are you sure you want to change the base?
[waiter-palypoo] ip #193
Changes from 1 commit
7faa1cb
0e9f153
565a8e1
3d00890
7e758c3
e13adce
752a280
c47e253
e40dfd0
203f936
367c9fd
65eef30
c890a60
07e9a22
1071390
3b7e16a
b0dc677
2f02a85
0e9aa9a
4af6cef
da2844c
4c64d87
bf6fe2d
4e01561
ecce69f
019af43
c915504
b195b1d
5a621ec
29dcae7
d207461
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import java.util.Scanner; | ||
|
||
public class HinaBot { | ||
protected static String[] taskList = new String[100]; | ||
protected static Task[] taskList = new Task[100]; | ||
protected static int taskCount = 0; | ||
public static void main(String[] args) { | ||
String line; | ||
|
@@ -26,21 +26,49 @@ public static void handleCommand(String command) { | |
else if (command.equalsIgnoreCase("list")) { | ||
listTasks(); | ||
} | ||
else if (command.split(" ")[0].equalsIgnoreCase("mark")) { | ||
int taskIndex = Integer.parseInt(command.split(" ")[1]); | ||
markTask(taskIndex); | ||
} | ||
else if (command.split(" ")[0].equalsIgnoreCase("unmark")) { | ||
int taskIndex = Integer.parseInt(command.split(" ")[1]); | ||
unmarkTask(taskIndex); | ||
} | ||
else { | ||
addTask(command); | ||
} | ||
} | ||
|
||
public static void addTask(String task) { | ||
taskList[taskCount] = task; | ||
public static void addTask(String description) { | ||
Task newTask = new Task(description); | ||
taskList[taskCount] = newTask; | ||
taskCount++; | ||
System.out.println("added: " + task); | ||
System.out.println("added: " + description); | ||
} | ||
|
||
public static void listTasks() { | ||
for (int i = 0; i < taskCount; i++) { | ||
System.out.print(i + 1); | ||
System.out.println(". " + taskList[i]); | ||
System.out.print(". "); | ||
if (taskList[i].isDone()) { | ||
System.out.print("[X] "); | ||
} | ||
else { | ||
System.out.print("[ ] "); | ||
} | ||
System.out.println(taskList[i].getDescription()); | ||
} | ||
} | ||
|
||
public static void markTask(int taskIndex) { | ||
taskList[taskIndex - 1].setDone(true); | ||
System.out.println("Roger that! This task is marked as done: "); | ||
System.out.println("[X] " + taskList[taskIndex - 1].getDescription()); | ||
} | ||
|
||
public static void unmarkTask(int taskIndex) { | ||
taskList[taskIndex - 1].setDone(false); | ||
System.out.println("Roger that! This task is marked as done: "); | ||
System.out.println("[ ] " + taskList[taskIndex - 1].getDescription()); | ||
} | ||
} | ||
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. Nice! 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. Nice! No Coding Violations 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. Good job! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class Task { | ||
private String description; | ||
private boolean isDone; | ||
public boolean isDone() { | ||
return isDone; | ||
} | ||
|
||
public void setDone(boolean done) { | ||
isDone = done; | ||
} | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
isDone = false; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
} | ||
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. Good job! |
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.
No coding violations at all!