Kaynağa Gözat

minor changes

Jennifer Chao 6 yıl önce
ebeveyn
işleme
d4a0e428f3

+ 23
- 9
Client/src/main/java/Console.java Dosyayı Görüntüle

@@ -4,44 +4,58 @@ public class Console {
4 4
 
5 5
     private static Scanner scanner = new Scanner(System.in);
6 6
 
7
-    public static String mainMenu() {
8
-        System.out.println("What would you like to do?" +
7
+    public static String printMainMenu() {
8
+        System.out.println("\nWhat would you like to do?" +
9 9
                 "\n> GET all users" +
10 10
                 "\n> ADD your information" +
11 11
                 "\n> SEND a message" +
12 12
                 "\n> SEE all messages" +
13 13
                 "\n> QUIT");
14
-        String option = scanner.nextLine().toUpperCase();
15
-        return option;
14
+        return scanner.nextLine().toUpperCase();
15
+    }
16
+
17
+    public static String printSendMenu() {
18
+        System.out.println("\nWhat type of message do you want to send?" +
19
+                "\n> GLOBAL message to everyone" +
20
+                "\n> DIRECT message to a specific user");
21
+        return scanner.nextLine().toUpperCase();
16 22
     }
17 23
 
18 24
     public static String getName() {
19
-        System.out.println("Please input your name: ");
25
+        System.out.println("\nPlease input your name: ");
20 26
         String name = scanner.nextLine();
21 27
         return name;
22 28
     }
23 29
 
24 30
     public static String getGithub() {
25
-        System.out.println("Please input your Github ID: ");
31
+        System.out.println("\nPlease input your Github ID: ");
26 32
         String github = scanner.nextLine();
27 33
         return github;
28 34
     }
29 35
 
30 36
     public static String getFromID() {
31
-        System.out.println("Please input your ID: ");
37
+        System.out.println("\nPlease input your ID: ");
32 38
         String github = scanner.nextLine();
33 39
         return github;
34 40
     }
35 41
 
36 42
     public static String getToID() {
37
-        System.out.println("Please input the receiver's ID: ");
43
+        System.out.println("\nPlease input the receiver's ID: ");
38 44
         String github = scanner.nextLine();
39 45
         return github;
40 46
     }
41 47
 
42 48
     public static String getMessage() {
43
-        System.out.println("Please input your message: ");
49
+        System.out.println("\nPlease input your message: ");
44 50
         String github = scanner.nextLine();
45 51
         return github;
46 52
     }
53
+
54
+    public static void printError(){
55
+        System.out.println("\nAn error has occurred.");
56
+    }
57
+
58
+    public static void printSuccess(String choice) {
59
+        System.out.println("\n" + choice + " success!");
60
+    }
47 61
 }

+ 23
- 3
Client/src/main/java/YouAreEll.java Dosyayı Görüntüle

@@ -1,3 +1,4 @@
1
+import com.fasterxml.jackson.databind.ObjectMapper;
1 2
 import com.mashape.unirest.http.HttpResponse;
2 3
 import com.mashape.unirest.http.JsonNode;
3 4
 import com.mashape.unirest.http.Unirest;
@@ -18,24 +19,30 @@ public class YouAreEll {
18 19
 
19 20
         boolean flag = true;
20 21
         while (flag) {
21
-            String userChoice = Console.mainMenu();
22
+            String userChoice = Console.printMainMenu();
22 23
             switch (userChoice) {
23 24
                 case "GET":
24 25
                     url.sendGetIDsRequest(url);
26
+                    Console.printSuccess(userChoice);
25 27
                     break;
26 28
                 case "ADD":
27 29
                     url.sendInputUserInfoRequest(url);
30
+                    Console.printSuccess(userChoice);
28 31
                     break;
29 32
                 case "SEND":
30
-                    url.sendGlobalMessageRequest(url);
31
-                    // url.sendDirectMessageRequest(url);
33
+                    url.sendMenu(Console.printSendMenu(), url);
34
+                    Console.printSuccess(userChoice);
32 35
                     break;
33 36
                 case "SEE":
34 37
                     url.sendGetGlobalMessagesRequest(url);
38
+                    Console.printSuccess(userChoice);
35 39
                     break;
36 40
                 case "QUIT":
37 41
                     flag = false;
38 42
                     break;
43
+                default:
44
+                    Console.printError();
45
+                    break;
39 46
             }
40 47
         }
41 48
 //        url.sendInputUserInfoRequest(url);
@@ -57,6 +64,19 @@ public class YouAreEll {
57 64
         return input;
58 65
     }
59 66
 
67
+    public void sendMenu(String sendOption, YouAreEll url) {
68
+        switch (sendOption) {
69
+            case "GLOBAL":
70
+                url.sendGlobalMessageRequest(url);
71
+                break;
72
+            case "DIRECT":
73
+                url.sendDirectMessageRequest(url);
74
+                break;
75
+            default:
76
+                break;
77
+        }
78
+    }
79
+
60 80
     public void inputUserInfo() throws UnirestException {
61 81
         String name = getInput(Console.getName());
62 82
         String github = getInput(Console.getGithub());