-
Notifications
You must be signed in to change notification settings - Fork 184
[Yao Chenguang] iP #182
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?
[Yao Chenguang] iP #182
Changes from 4 commits
53b69a6
b813825
23f5257
3091a14
b16481d
4c0c74d
164fe07
e8763fb
39f4bc6
1404793
2bb0d47
0fe72dc
9c842cb
76fb54f
b96d7f5
6f1bd63
405db82
651295e
c00f1e8
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,62 @@ | ||
| import javax.swing.*; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Qchat { | ||
|
|
||
| static final String WELCOME_GREETING = new String( | ||
| "Qchat ,A truly humanized intelligent voice assisstant \n" | ||
| +"knows better about life and better about you\n" | ||
| +"What can I do for you?\n" | ||
| +"----------------------------------------------------------------\n") ; | ||
| static final String GOODBYE_GREETING = new String( | ||
| "--------------------------------------------------------\n" + | ||
| "goodbye\n"+ "Qchat, your life-long trusted companion\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. You may want to reduce the number of line breaks. |
||
| static String CommandReader(){ | ||
|
|
||
| Scanner in = new Scanner(System.in); | ||
| String command ; | ||
| command = in.nextLine(); | ||
|
|
||
| switch (command){ | ||
| case "Bye": | ||
| System.out.print(GOODBYE_GREETING); | ||
| break; | ||
| case "list": | ||
| Todolist.HandleList(); | ||
| break; | ||
|
|
||
|
|
||
| default: | ||
| echo(command); | ||
| break; | ||
|
|
||
| } | ||
|
Comment on lines
+24
to
+26
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 is the other commands such as quit, help, mark, unmark etc. only accessible after the user input list? |
||
| return command; | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| private static void echo(String command) { | ||
| System.out.print("---------------------------------------------\n"); | ||
| System.out.print(command +"\n"); | ||
| System.out.print("---------------------------------------------\n"); | ||
|
Comment on lines
+34
to
+36
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 would suggest using System.lineSeparator() instead of "\n" for code compatibility with other systems. |
||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| System.out.print(WELCOME_GREETING); | ||
| String command = "" ; | ||
| while(!command.equals("Bye")){ | ||
|
|
||
| command = CommandReader(); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Todolist { | ||
| private static final int MAX_LIST_LENGTH = 100; | ||
| static String[] todolist = new String[MAX_LIST_LENGTH]; | ||
| static boolean[] isDoneList = new boolean[MAX_LIST_LENGTH]; | ||
|
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 a static final int, instead of specifying "100" directly in the array as you have avoided using magic numbers. |
||
|
|
||
| static int ListCount= 0; | ||
| static Scanner in = new Scanner(System.in); | ||
|
|
||
| public static void AddToList(){ | ||
| String Task= in.nextLine(); | ||
| todolist[ListCount] = Task; | ||
| isDoneList[ListCount]= false; | ||
| ListCount++; | ||
| return; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static void HandleList(){ | ||
| PrintList(); | ||
| String command =""; | ||
|
|
||
| while(!command.equals("quit")){ | ||
| command = in.nextLine(); | ||
| switch (command){ | ||
| case"add": | ||
| AddToList(); | ||
| System.out.println("Task added"); | ||
| PrintList(); | ||
| break; | ||
| case"quit": | ||
| System.out.println("Task change complete"); | ||
| break; | ||
| case"help": | ||
| System.out.print("supported commands: add , quit , help , mark,unmark ,clear, list\n"); | ||
| break; | ||
| case "clear": | ||
| ClearList(); | ||
| ClearisDoneList(); | ||
| System.out.print("list cleared\n"); | ||
| break; | ||
| case"mark": | ||
| SetDone(); | ||
| break; | ||
| case"unmark": | ||
| SetUndone(); | ||
| break; | ||
| case"list": | ||
| PrintList(); | ||
| break; | ||
| case"": | ||
| break; | ||
| default: | ||
| System.out.println("Sorry, I can not understand this command, enter \"help\" for help\n"); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| public static void PrintList(){ | ||
| int i=1; | ||
| System.out.print("---------------------------------------------\n"); | ||
| System.out.println("Here are your current tasks in your list:"); | ||
| for (String s :todolist ){ | ||
| if(s == null){ | ||
| continue; | ||
| } | ||
| System.out.printf("%d."+GetIcon(i)+s+"\n",i); | ||
|
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 may want to add spaced before and after the "+", this is part of coding standards. |
||
| i++; | ||
| } | ||
| System.out.print("---------------------------------------------\n"); | ||
| } | ||
| static void ClearList(){ | ||
| int i; | ||
| for (i=0;i<MAX_LIST_LENGTH;i++){ | ||
| todolist[i]=null; | ||
| } | ||
| ListCount = 0; | ||
| } | ||
|
|
||
| static void ClearisDoneList(){ | ||
| int i; | ||
| for (i=0;i<MAX_LIST_LENGTH;i++){ | ||
| isDoneList[i]=false; | ||
| } | ||
| } | ||
|
|
||
| static String GetIcon(int i){ | ||
| String s= isDoneList[i-1]?"x":" "; | ||
| return "["+s+"]"; | ||
| } | ||
|
|
||
| static void SetDone(){ | ||
| System.out.println("please type the task number you want to set as done \n"); | ||
| PrintList(); | ||
| int number= in.nextInt(); | ||
|
|
||
| while(number>ListCount){ | ||
| System.out.println("task do not exist, pleas enter a valid task number "); | ||
| number= in.nextInt(); | ||
| } | ||
|
|
||
| isDoneList[number-1]=true; | ||
| System.out.print("I've marked this task as done:"); | ||
| System.out.printf(GetIcon(number)+todolist[number-1]+"\n"); | ||
| } | ||
|
|
||
| static void SetUndone(){ | ||
| System.out.println("please type the task number you want to set as not done \n"); | ||
| PrintList(); | ||
| int number= in.nextInt(); | ||
|
|
||
| while(number>ListCount){ | ||
| System.out.println("task do not exist, pleas enter a valid task number "); | ||
| number= in.nextInt(); | ||
| } | ||
|
|
||
| isDoneList[number-1]=false; | ||
| System.out.print("I've marked this task as not done:"); | ||
| System.out.printf(GetIcon(number)+todolist[number-1]+"\n"); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
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.
Would it be better to not import all packages although according to google it is lightweight.