-
Notifications
You must be signed in to change notification settings - Fork 78
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
[Chua Zhong Heng] iP #63
base: master
Are you sure you want to change the base?
Changes from 5 commits
cefd18d
a30a0be
ff4554d
899542c
cd10722
95c15bd
3d50f0a
c7b6dac
a5d5914
50f175c
8e1aead
3dbdfbc
544d7c9
060f8b7
712e602
20a68c2
16e8cbf
5cfdcb5
8ff14d8
335ff3f
578c87e
ca8c8e3
23dfdee
ee3e90e
fe43edd
b7a4dd3
f583868
6b15613
4c2227f
0a23d97
0e39d2e
e8b4ef4
32f1853
96ac6d1
f41f811
b3bcec5
d0f4404
f6ef0c4
5d0ee0d
2ff6d44
9f93c2e
a077f54
bd265bb
e6b2f51
449b98d
bfdc87d
fb8bcff
f691c78
8f7dbd9
531399a
9b0876a
d17d6b4
7ee1694
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,97 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Nuke { | ||
|
||
public static void printGreetingMessage() { | ||
printLine(); | ||
System.out.println(" Hello! I'm Nuke\n" + " What can I do for you?"); | ||
printLine(); | ||
} | ||
|
||
public static void printExitMessage() { | ||
printLine(); | ||
System.out.println(" Bye. Hope to see you again soon!"); | ||
printLine(); | ||
} | ||
|
||
public static void printLine() { | ||
System.out.println(" ____________________________________________________________"); | ||
} | ||
|
||
public static void echo() { | ||
Scanner input = new Scanner(System.in); | ||
String item = input.nextLine(); | ||
if (item.equals("bye")) { | ||
printExitMessage(); | ||
return; | ||
} else { | ||
printLine(); | ||
System.out.println(item); | ||
printLine(); | ||
echo(); | ||
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! |
||
} | ||
} | ||
|
||
public static void dialogue(ArrayList<String> itemList, ArrayList<String> markList) { | ||
Scanner input = new Scanner(System.in); | ||
String item = input.nextLine(); | ||
if (item.equals("bye")) { | ||
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 that you use else-if instead of nesting 👍 |
||
printExitMessage(); | ||
return; | ||
} else if (item.equals("list")) { | ||
list(itemList, markList); | ||
} else if (item.length() > 4 && item.substring(0, 4).equals("mark")) { | ||
String[] splitItem = item.split(" "); | ||
int listIndex = Integer.parseInt(splitItem[1]); | ||
mark(itemList, markList, listIndex); | ||
} else if (item.length() > 6 && item.substring(0, 6).equals("unmark")) { | ||
String[] splitItem = item.split(" "); | ||
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. Could this array be named "items" instead? |
||
int listIndex = Integer.parseInt(splitItem[1]); | ||
unmark(itemList, markList, listIndex); | ||
} else { | ||
add(itemList, markList, item); | ||
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. indentations just require one more space |
||
} | ||
dialogue(itemList, markList); | ||
} | ||
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 use of naming standards, e.g camelCase |
||
|
||
public static void add(ArrayList<String> itemList, ArrayList<String> markList, String item) { | ||
printLine(); | ||
itemList.add(item); | ||
markList.add("[ ]"); | ||
System.out.printf(" added: %s\n", item); | ||
printLine(); | ||
} | ||
|
||
public static void list(ArrayList<String> itemList, ArrayList<String> markList) { | ||
printLine(); | ||
System.out.println(" Here are the tasks in your list:"); | ||
for (int i = 0; i < itemList.size(); i++) { | ||
System.out.printf(" %d.%s %s\n", i+1, markList.get(i), itemList.get(i)); | ||
} | ||
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. Good layout structure |
||
public static void mark(ArrayList<String> itemList, ArrayList<String> markList, int listIndex) { | ||
printLine(); | ||
System.out.println(" Nice! I've marked this task as done:"); | ||
markList.set(listIndex - 1, "[X]"); | ||
System.out.printf(" %s %s\n", markList.get(listIndex - 1), itemList.get(listIndex - 1)); | ||
printLine(); | ||
} | ||
|
||
public static void unmark(ArrayList<String> itemList, ArrayList<String> markList, int listIndex) { | ||
printLine(); | ||
System.out.println(" OK, I've marked this task as not done yet:"); | ||
markList.set(listIndex - 1, "[ ]"); | ||
System.out.printf(" %s %s\n", markList.get(listIndex - 1), itemList.get(listIndex - 1)); | ||
printLine(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
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 that your main method is short and neat :D |
||
printGreetingMessage(); | ||
ArrayList<String> itemList = new ArrayList<String>(); | ||
ArrayList<String> markList = new ArrayList<String>(); | ||
dialogue(itemList, markList); | ||
} | ||
} |
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.
Can consider adding javadoc comments for each method for greater clarity.