-
Notifications
You must be signed in to change notification settings - Fork 197
[kagiura] iP #208
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?
[kagiura] iP #208
Changes from 3 commits
01b61c9
43d34ef
7796838
64ccab7
3e2bd41
e5d9ddf
6a25e19
f6832d8
a5aaf5d
41056b3
2e25409
a288193
6c436bf
682b7ea
f0cc6a0
31b3d1a
028c812
b28de87
3e40dd5
bf20df9
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,20 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X | ||
| } | ||
|
|
||
| public void print() { | ||
| System.out.print("[" + (isDone ? "X" : " ") + "] "); | ||
| System.out.println(description); | ||
| } | ||
|
|
||
| //... | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Wen { | ||
|
|
||
| private static int taskCount = 0; | ||
| private static Task[] tasks = new Task[100]; | ||
|
|
||
| public static void main(String[] args) { | ||
| initializeAndGreet(); | ||
|
|
||
| String input = ""; | ||
| Scanner in = new Scanner(System.in); | ||
|
|
||
| while (!input.equals("bye")) { | ||
|
||
| input = in.nextLine(); | ||
| final String command = input.split(" ", 2)[0]; | ||
| final String commandArgs = input.split(" ", 2).length > 1 ? input.split(" ", 2)[1] : ""; | ||
|
|
||
| switch (command) { | ||
|
||
| case "bye": | ||
| break; | ||
|
|
||
| case "list": | ||
| printTasks(); | ||
| break; | ||
|
|
||
|
|
||
|
|
||
| default: | ||
| addTask(input); | ||
| // System.out.println("Unknown command \""+command+"\"! Double check your message and try running again~"); | ||
|
||
| break; | ||
| } | ||
| } | ||
|
|
||
| terminateAndGoodbye(); | ||
| } | ||
|
|
||
|
|
||
| private static void initializeAndGreet() { | ||
| System.out.println("Hello, I'm Wen!"); | ||
| System.out.println("Let me know what I can help you with~☆"); | ||
| } | ||
|
|
||
| private static void terminateAndGoodbye() { | ||
| System.out.println(); | ||
| System.out.println("Aw, you're already going?"); | ||
| System.out.println("It's okay, let's meet again soon!"); | ||
|
|
||
| System.exit(0); | ||
| } | ||
|
|
||
| private static void printTasks() { | ||
| System.out.println("You currently have " + taskCount + " tasks!"); | ||
| for (int i=0; i<taskCount; i++) { | ||
| tasks[i].print(); | ||
| } | ||
| } | ||
|
|
||
| private static void addTask(String description) { | ||
| tasks[taskCount] = new Task(description); | ||
|
|
||
| System.out.println("Task added succesfully:"); | ||
| tasks[taskCount].print(); | ||
|
|
||
| taskCount++; | ||
| } | ||
| } | ||
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.
avoid using magic numbers, declare 100 as a constant like TASKS_SIZE