Pārlūkot izejas kodu

prints and methods on point

Demetrius Murray 6 gadus atpakaļ
vecāks
revīzija
669765554c

+ 117
- 51
.idea/workspace.xml Parādīt failu

@@ -3,6 +3,11 @@
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="6579b631-ed88-494a-87f6-48ccbc3e224e" name="Default Changelist" comment="">
5 5
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/src/main/java/AccountApp.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AccountApp.java" afterDir="false" />
7
+      <change beforePath="$PROJECT_DIR$/src/main/java/Console.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Console.java" afterDir="false" />
8
+      <change beforePath="$PROJECT_DIR$/src/main/java/MySqlDriver.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/MySqlDriver.java" afterDir="false" />
9
+      <change beforePath="$PROJECT_DIR$/target/classes/AccountApp.class" beforeDir="false" />
10
+      <change beforePath="$PROJECT_DIR$/target/classes/Console.class" beforeDir="false" />
6 11
     </list>
7 12
     <ignored path="$PROJECT_DIR$/out/" />
8 13
     <ignored path="$PROJECT_DIR$/target/" />
@@ -64,7 +69,7 @@
64 69
         <counts>
65 70
           <entry key="account" value="2" />
66 71
           <entry key="class" value="13" />
67
-          <entry key="java" value="12" />
72
+          <entry key="java" value="14" />
68 73
           <entry key="sql" value="4" />
69 74
           <entry key="xml" value="6" />
70 75
         </counts>
@@ -73,7 +78,7 @@
73 78
         <counts>
74 79
           <entry key="CLASS" value="13" />
75 80
           <entry key="Database Element" value="2" />
76
-          <entry key="JAVA" value="12" />
81
+          <entry key="JAVA" value="14" />
77 82
           <entry key="Scratch" value="4" />
78 83
           <entry key="XML" value="6" />
79 84
         </counts>
@@ -81,7 +86,7 @@
81 86
       <usages-collector id="statistics.file.extensions.edit">
82 87
         <counts>
83 88
           <entry key="dummy" value="2" />
84
-          <entry key="java" value="14792" />
89
+          <entry key="java" value="16546" />
85 90
           <entry key="sql" value="101" />
86 91
           <entry key="txt" value="26" />
87 92
           <entry key="xml" value="20" />
@@ -89,7 +94,7 @@
89 94
       </usages-collector>
90 95
       <usages-collector id="statistics.file.types.edit">
91 96
         <counts>
92
-          <entry key="JAVA" value="14792" />
97
+          <entry key="JAVA" value="16546" />
93 98
           <entry key="PLAIN_TEXT" value="28" />
94 99
           <entry key="Scratch" value="101" />
95 100
           <entry key="XML" value="20" />
@@ -98,14 +103,14 @@
98 103
     </session>
99 104
   </component>
100 105
   <component name="FileEditorManager">
101
-    <splitter split-orientation="horizontal" split-proportion="0.4894163">
106
+    <splitter split-orientation="horizontal" split-proportion="0.47337595">
102 107
       <split-first>
103 108
         <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
104
-          <file pinned="false" current-in-tab="true">
109
+          <file pinned="false" current-in-tab="false">
105 110
             <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
106 111
               <provider selected="true" editor-type-id="text-editor">
107
-                <state relative-caret-position="330">
108
-                  <caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
112
+                <state relative-caret-position="-1032">
113
+                  <caret line="84" column="33" selection-start-line="84" selection-start-column="33" selection-end-line="84" selection-end-column="33" />
109 114
                   <folding>
110 115
                     <element signature="imports" expanded="true" />
111 116
                   </folding>
@@ -127,7 +132,7 @@
127 132
               </provider>
128 133
             </entry>
129 134
           </file>
130
-          <file pinned="false" current-in-tab="false">
135
+          <file pinned="false" current-in-tab="true">
131 136
             <entry file="file://$PROJECT_DIR$/src/test/java/MySqlDriveTest.java">
132 137
               <provider selected="true" editor-type-id="text-editor">
133 138
                 <state relative-caret-position="180">
@@ -203,18 +208,46 @@
203 208
       <split-second>
204 209
         <leaf>
205 210
           <file pinned="false" current-in-tab="false">
206
-            <entry file="file://$PROJECT_DIR$/src/main/java/MySqlDriver.java">
211
+            <entry file="file://$PROJECT_DIR$/src/main/java/Console.java">
207 212
               <provider selected="true" editor-type-id="text-editor">
208
-                <state relative-caret-position="130">
209
-                  <caret line="19" column="10" selection-start-line="19" selection-start-column="10" selection-end-line="19" selection-end-column="10" />
213
+                <state relative-caret-position="179">
214
+                  <caret line="83" column="56" selection-start-line="83" selection-start-column="56" selection-end-line="83" selection-end-column="56" />
210 215
                   <folding>
211 216
                     <element signature="imports" expanded="true" />
217
+                    <element signature="e#714#715#0" expanded="true" />
218
+                    <element signature="e#773#774#0" expanded="true" />
219
+                    <element signature="e#720#721#0" expanded="true" />
220
+                    <element signature="e#768#769#0" expanded="true" />
221
+                    <element signature="e#803#804#0" expanded="true" />
222
+                    <element signature="e#856#857#0" expanded="true" />
223
+                    <element signature="e#894#895#0" expanded="true" />
224
+                    <element signature="e#953#954#0" expanded="true" />
225
+                    <element signature="e#808#809#0" expanded="true" />
226
+                    <element signature="e#850#851#0" expanded="true" />
227
+                    <element signature="e#1092#1093#0" expanded="true" />
228
+                    <element signature="e#1117#1118#0" expanded="true" />
229
+                    <element signature="e#1177#1178#0" expanded="true" />
230
+                    <element signature="e#1236#1237#0" expanded="true" />
231
+                    <element signature="e#1177#1178#0" expanded="true" />
232
+                    <element signature="e#1202#1203#0" expanded="true" />
212 233
                   </folding>
213 234
                 </state>
214 235
               </provider>
215 236
             </entry>
216 237
           </file>
217 238
           <file pinned="false" current-in-tab="true">
239
+            <entry file="file://$PROJECT_DIR$/src/main/java/MySqlDriver.java">
240
+              <provider selected="true" editor-type-id="text-editor">
241
+                <state relative-caret-position="-432">
242
+                  <caret line="19" column="31" selection-start-line="19" selection-start-column="31" selection-end-line="19" selection-end-column="31" />
243
+                  <folding>
244
+                    <element signature="imports" expanded="true" />
245
+                  </folding>
246
+                </state>
247
+              </provider>
248
+            </entry>
249
+          </file>
250
+          <file pinned="false" current-in-tab="false">
218 251
             <entry file="das://9431aac8-f492-452b-bef7-9dfc00b1f123/schema/orm_lab/table/account">
219 252
               <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
220 253
                 <state>
@@ -244,6 +277,8 @@
244 277
       <find>delete</find>
245 278
       <find>queryForAll</find>
246 279
       <find>databasetyp</find>
280
+      <find>updateBy</find>
281
+      <find>toStrin</find>
247 282
     </findStrings>
248 283
   </component>
249 284
   <component name="Git.Settings">
@@ -253,7 +288,6 @@
253 288
     <option name="CHANGED_PATHS">
254 289
       <list>
255 290
         <option value="$APPLICATION_CONFIG_DIR$/consoles/db/9431aac8-f492-452b-bef7-9dfc00b1f123/console.sql" />
256
-        <option value="$PROJECT_DIR$/src/main/java/Console.java" />
257 291
         <option value="$PROJECT_DIR$/src/main/java/MySQLDriver.java" />
258 292
         <option value="$PROJECT_DIR$/src/test/java/MySqlDriverTest2.java" />
259 293
         <option value="$PROJECT_DIR$/pom.xml" />
@@ -263,6 +297,7 @@
263 297
         <option value="$PROJECT_DIR$/src/main/java/MockDao.java" />
264 298
         <option value="$PROJECT_DIR$/src/test/java/MySqlDriveTest.java" />
265 299
         <option value="$PROJECT_DIR$/src/main/java/MySqlDriver.java" />
300
+        <option value="$PROJECT_DIR$/src/main/java/Console.java" />
266 301
         <option value="$PROJECT_DIR$/src/main/java/AccountApp.java" />
267 302
       </list>
268 303
     </option>
@@ -347,7 +382,7 @@
347 382
     <property name="DatabaseDriversLRU" value="mysql" />
348 383
     <property name="WebServerToolWindowFactoryState" value="false" />
349 384
     <property name="aspect.path.notification.shown" value="true" />
350
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542496510333" />
385
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542501272481" />
351 386
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="Arquillian JUnit4" />
352 387
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.Arquillian JUnit4" value="" />
353 388
     <property name="database.console.LAST_STATE" value="false" />
@@ -377,7 +412,7 @@
377 412
       </list>
378 413
     </option>
379 414
   </component>
380
-  <component name="RunManager" selected="Application.AccountApp">
415
+  <component name="RunManager" selected="JUnit.MySqlDriveTest">
381 416
     <configuration name="AccountApp" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
382 417
       <option name="MAIN_CLASS_NAME" value="AccountApp" />
383 418
       <module name="ORMLite" />
@@ -432,11 +467,11 @@
432 467
     </list>
433 468
     <recent_temporary>
434 469
       <list>
470
+        <item itemvalue="JUnit.MySqlDriveTest" />
435 471
         <item itemvalue="Application.AccountApp" />
436 472
         <item itemvalue="JUnit.MySqlDriveTest.updatePassword" />
437 473
         <item itemvalue="JUnit.MySqlDriveTest.updateName" />
438 474
         <item itemvalue="JUnit.MySqlDriveTest.testUpdate" />
439
-        <item itemvalue="JUnit.MySqlDriveTest" />
440 475
       </list>
441 476
     </recent_temporary>
442 477
   </component>
@@ -452,7 +487,7 @@
452 487
       <updated>1542309696171</updated>
453 488
       <workItem from="1542309702788" duration="18534000" />
454 489
       <workItem from="1542335736358" duration="6697000" />
455
-      <workItem from="1542378639704" duration="22213000" />
490
+      <workItem from="1542378639704" duration="27119000" />
456 491
     </task>
457 492
     <servers />
458 493
   </component>
@@ -489,7 +524,7 @@
489 524
     </history-entry>
490 525
   </component>
491 526
   <component name="TimeTrackingManager">
492
-    <option name="totallyTimeSpent" value="47444000" />
527
+    <option name="totallyTimeSpent" value="52350000" />
493 528
   </component>
494 529
   <component name="TodoView">
495 530
     <todo-panel id="selected-file">
@@ -502,8 +537,9 @@
502 537
   </component>
503 538
   <component name="ToolWindowManager">
504 539
     <frame x="-333" y="-1080" width="1920" height="1080" extended-state="0" />
540
+    <editor active="true" />
505 541
     <layout>
506
-      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.08146965" />
542
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.12193823" />
507 543
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
508 544
       <window_info id="Image Layers" order="2" />
509 545
       <window_info id="Designer" order="3" />
@@ -512,7 +548,7 @@
512 548
       <window_info id="Favorites" order="6" side_tool="true" />
513 549
       <window_info anchor="bottom" id="Message" order="0" />
514 550
       <window_info anchor="bottom" id="Find" order="1" weight="0.32928064" />
515
-      <window_info anchor="bottom" id="Run" order="2" weight="0.18034448" />
551
+      <window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.45187438" />
516 552
       <window_info anchor="bottom" id="Debug" order="3" weight="0.39918947" />
517 553
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
518 554
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -520,7 +556,7 @@
520 556
       <window_info anchor="bottom" id="Database Console" order="7" weight="0.2234795" />
521 557
       <window_info anchor="bottom" id="Version Control" order="8" show_stripe_button="false" />
522 558
       <window_info anchor="bottom" id="Database Changes" order="9" />
523
-      <window_info active="true" anchor="bottom" id="Terminal" order="10" visible="true" weight="0.32928064" />
559
+      <window_info anchor="bottom" id="Terminal" order="10" weight="0.14994934" />
524 560
       <window_info anchor="bottom" id="Event Log" order="11" side_tool="true" />
525 561
       <window_info anchor="bottom" id="Messages" order="12" weight="0.32928064" />
526 562
       <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
@@ -528,7 +564,7 @@
528 564
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
529 565
       <window_info anchor="right" id="Palette" order="3" />
530 566
       <window_info anchor="right" id="Capture Analysis" order="4" />
531
-      <window_info anchor="right" id="Database" order="5" visible="true" weight="0.08839191" />
567
+      <window_info anchor="right" id="Database" order="5" weight="0.08839191" />
532 568
       <window_info anchor="right" id="Theme Preview" order="6" />
533 569
       <window_info anchor="right" id="Palette&#9;" order="7" />
534 570
       <window_info anchor="right" id="Maven Projects" order="8" />
@@ -540,6 +576,20 @@
540 576
   <component name="VcsContentAnnotationSettings">
541 577
     <option name="myLimit" value="2678400000" />
542 578
   </component>
579
+  <component name="XDebuggerManager">
580
+    <breakpoint-manager>
581
+      <breakpoints>
582
+        <line-breakpoint enabled="true" type="java-method">
583
+          <url>file://$PROJECT_DIR$/src/main/java/Console.java</url>
584
+          <line>81</line>
585
+          <properties class="Console" method="printAccounts">
586
+            <option name="EMULATED" value="true" />
587
+          </properties>
588
+          <option name="timeStamp" value="2" />
589
+        </line-breakpoint>
590
+      </breakpoints>
591
+    </breakpoint-manager>
592
+  </component>
543 593
   <component name="editorHistoryManager">
544 594
     <entry file="file://$APPLICATION_CONFIG_DIR$/consoles/db/163f7846-9e5c-46db-81c7-61098b9d157e/console.sql">
545 595
       <provider selected="true" editor-type-id="text-editor" />
@@ -568,16 +618,6 @@
568 618
         </state>
569 619
       </provider>
570 620
     </entry>
571
-    <entry file="file://$PROJECT_DIR$/src/main/java/Console.java">
572
-      <provider selected="true" editor-type-id="text-editor">
573
-        <state relative-caret-position="465">
574
-          <caret line="35" selection-start-line="35" selection-end-line="35" />
575
-          <folding>
576
-            <element signature="imports" expanded="true" />
577
-          </folding>
578
-        </state>
579
-      </provider>
580
-    </entry>
581 621
     <entry file="file://$PROJECT_DIR$/src/test/java/MySqlDriverTest2.java" />
582 622
     <entry file="file://$PROJECT_DIR$/pom.xml">
583 623
       <provider selected="true" editor-type-id="text-editor">
@@ -716,16 +756,6 @@
716 756
         </state>
717 757
       </provider>
718 758
     </entry>
719
-    <entry file="file://$PROJECT_DIR$/src/test/java/MySqlDriveTest.java">
720
-      <provider selected="true" editor-type-id="text-editor">
721
-        <state relative-caret-position="180">
722
-          <caret line="23" column="40" selection-start-line="23" selection-start-column="40" selection-end-line="23" selection-end-column="40" />
723
-          <folding>
724
-            <element signature="imports" expanded="true" />
725
-          </folding>
726
-        </state>
727
-      </provider>
728
-    </entry>
729 759
     <entry file="file://$APPLICATION_CONFIG_DIR$/consoles/db/9431aac8-f492-452b-bef7-9dfc00b1f123/console.sql">
730 760
       <provider selected="true" editor-type-id="text-editor">
731 761
         <state relative-caret-position="135">
@@ -745,27 +775,63 @@
745 775
         </state>
746 776
       </provider>
747 777
     </entry>
748
-    <entry file="file://$PROJECT_DIR$/src/main/java/MySqlDriver.java">
778
+    <entry file="das://9431aac8-f492-452b-bef7-9dfc00b1f123/schema/orm_lab/table/account">
779
+      <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
780
+        <state>
781
+          <filtering enabled="true" />
782
+        </state>
783
+      </provider>
784
+    </entry>
785
+    <entry file="file://$PROJECT_DIR$/src/main/java/Console.java">
749 786
       <provider selected="true" editor-type-id="text-editor">
750
-        <state relative-caret-position="130">
751
-          <caret line="19" column="10" selection-start-line="19" selection-start-column="10" selection-end-line="19" selection-end-column="10" />
787
+        <state relative-caret-position="179">
788
+          <caret line="83" column="56" selection-start-line="83" selection-start-column="56" selection-end-line="83" selection-end-column="56" />
752 789
           <folding>
753 790
             <element signature="imports" expanded="true" />
791
+            <element signature="e#714#715#0" expanded="true" />
792
+            <element signature="e#773#774#0" expanded="true" />
793
+            <element signature="e#720#721#0" expanded="true" />
794
+            <element signature="e#768#769#0" expanded="true" />
795
+            <element signature="e#803#804#0" expanded="true" />
796
+            <element signature="e#856#857#0" expanded="true" />
797
+            <element signature="e#894#895#0" expanded="true" />
798
+            <element signature="e#953#954#0" expanded="true" />
799
+            <element signature="e#808#809#0" expanded="true" />
800
+            <element signature="e#850#851#0" expanded="true" />
801
+            <element signature="e#1092#1093#0" expanded="true" />
802
+            <element signature="e#1117#1118#0" expanded="true" />
803
+            <element signature="e#1177#1178#0" expanded="true" />
804
+            <element signature="e#1236#1237#0" expanded="true" />
805
+            <element signature="e#1177#1178#0" expanded="true" />
806
+            <element signature="e#1202#1203#0" expanded="true" />
754 807
           </folding>
755 808
         </state>
756 809
       </provider>
757 810
     </entry>
758
-    <entry file="das://9431aac8-f492-452b-bef7-9dfc00b1f123/schema/orm_lab/table/account">
759
-      <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
760
-        <state>
761
-          <filtering enabled="true" />
811
+    <entry file="file://$PROJECT_DIR$/src/main/java/MySqlDriver.java">
812
+      <provider selected="true" editor-type-id="text-editor">
813
+        <state relative-caret-position="-432">
814
+          <caret line="19" column="31" selection-start-line="19" selection-start-column="31" selection-end-line="19" selection-end-column="31" />
815
+          <folding>
816
+            <element signature="imports" expanded="true" />
817
+          </folding>
762 818
         </state>
763 819
       </provider>
764 820
     </entry>
765 821
     <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
766 822
       <provider selected="true" editor-type-id="text-editor">
767
-        <state relative-caret-position="330">
768
-          <caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
823
+        <state relative-caret-position="-1032">
824
+          <caret line="84" column="33" selection-start-line="84" selection-start-column="33" selection-end-line="84" selection-end-column="33" />
825
+          <folding>
826
+            <element signature="imports" expanded="true" />
827
+          </folding>
828
+        </state>
829
+      </provider>
830
+    </entry>
831
+    <entry file="file://$PROJECT_DIR$/src/test/java/MySqlDriveTest.java">
832
+      <provider selected="true" editor-type-id="text-editor">
833
+        <state relative-caret-position="180">
834
+          <caret line="23" column="40" selection-start-line="23" selection-start-column="40" selection-end-line="23" selection-end-column="40" />
769 835
           <folding>
770 836
             <element signature="imports" expanded="true" />
771 837
           </folding>

+ 0
- 3
src/main/java/Account.java Parādīt failu

@@ -1,9 +1,6 @@
1 1
 import com.j256.ormlite.field.DatabaseField;
2 2
 import com.j256.ormlite.table.DatabaseTable;
3 3
 
4
-import java.util.ArrayList;
5
-import java.util.List;
6
-
7 4
 @DatabaseTable(tableName = "account")
8 5
 public class Account {
9 6
 

+ 26
- 31
src/main/java/AccountApp.java Parādīt failu

@@ -6,7 +6,6 @@ import com.j256.ormlite.support.ConnectionSource;
6 6
 import java.sql.SQLException;
7 7
 import java.util.List;
8 8
 
9
-//TODO clean print methods.
10 9
 // todo tests.
11 10
 public class AccountApp {
12 11
     private static final String DATABASE_URL = "jdbc:mysql://localhost:3306/orm_lab?useUnicode=true";
@@ -29,22 +28,20 @@ public class AccountApp {
29 28
             setupDao(connectionSource);
30 29
             mySqlDriver = new MySqlDriver(accountDao);
31 30
 
32
-            console.println("Welcome to the Account Database.");
33
-            String menu = "menu";
34
-            console.println(menu);
31
+            console.welcome();
35 32
             boolean open = true;
36 33
             while (open){
37
-                String input = console.getStringInput(">> select an option:" + " [ new account ] [ update ] [ query ] [ delete ]\n" +
38
-                        ">> or [ quit ] to close program");
34
+                String input = console.mainMenu();
39 35
                 if (!String.valueOf(input).trim().equals("quit")) {
40 36
                     try {
41 37
                         crudOperations(String.valueOf(input).trim());
42 38
                     } catch (NullPointerException np) {
43
-                        console.println(">> returned to main menu");
39
+                    } finally {
40
+                        console.returnToMain();
44 41
                     }
45 42
                 } else {
46 43
                     open = false;
47
-                    console.println("[ peace ]");
44
+                    console.goodBye();
48 45
                 }
49 46
             }
50 47
 
@@ -59,28 +56,27 @@ public class AccountApp {
59 56
             newAccount();
60 57
         } else if (input.equals("update")) {
61 58
             try {
62
-                Account acct = mySqlDriver.selectAccount(
63
-                        console.getIntegerInput(">> enter account ID to update"));
64
-                update(acct);
59
+                Account acct = mySqlDriver.selectAccount(console.getId());
60
+                updateBy(acct);
65 61
             } catch (IndexOutOfBoundsException np) {
66
-                console.println("\n:: account does not exist ::\n");
62
+                console.accountDNE();
67 63
             }
68 64
         } else if (input.equals("query")) {
69
-            query().forEach(e->console.println(e.toString()));
65
+            console.printAccounts(query());
70 66
         } else if (input.equals("delete")) {
71 67
             delete();
72 68
         }
73 69
     }
74 70
 
75 71
     private void newAccount() throws Exception {
76
-        String name = console.getStringInput(">> enter name");
77
-        String p = console.getStringInput(">> enter password");
72
+        String name = console.getName();
73
+        String p = console.getPassword();
78 74
         Account account = new Account(name, p);
79 75
         mySqlDriver.create(account);
80 76
     }
81 77
 
82
-    private void update(Account accounts) throws Exception{
83
-        String input = console.getStringInput(">> options: name | password | account");
78
+    private void updateBy(Account accounts) throws Exception{
79
+        String input = console.getBy("update");
84 80
             if (String.valueOf(input).trim().equals("password")) {
85 81
                 updatePassword(accounts);
86 82
             } else if (String.valueOf(input).trim().equals("name")) {
@@ -93,19 +89,19 @@ public class AccountApp {
93 89
  //   }
94 90
 
95 91
     private void updateName(Account account) throws SQLException{
96
-        String name = console.getStringInput(">> Enter name");
92
+        String name = console.getName();
97 93
         account.setName(name);
98 94
         mySqlDriver.updateName(account, name);
99 95
     }
100 96
     private void updatePassword(Account account) throws SQLException {
101
-        String pw = console.getStringInput(">> Enter password");
97
+        String pw = console.getPassword();
102 98
         account.setPassword(pw);
103 99
         mySqlDriver.update(account);
104 100
     }
105 101
 
106 102
     private List<Account> query() throws SQLException{
107 103
         List<Account> query = null;
108
-        String input = console.getStringInput(">> query: [ all ] or [ by ]\n>> or [ back ] to return");
104
+        String input = console.getAllorBy("query");
109 105
 
110 106
         if (String.valueOf(input).trim().equals("all")) {
111 107
             query = queryAll();
@@ -126,18 +122,18 @@ public class AccountApp {
126 122
     }
127 123
 
128 124
     private List<Account> queryBy() throws SQLException {
129
-        String input = console.getStringInput(">> query by: [ name ] , [ id ] , or [ password ]\n>> or [ back ] to return");
125
+        String input = console.getBy("query");
130 126
 
131 127
         if (String.valueOf(input).trim().equals("name")) {
132
-            String in = console.getStringInput(">> enter name:");
128
+            String in = console.getName();
133 129
             return mySqlDriver.queryName(in);
134 130
 
135 131
         } else if (String.valueOf(input).trim().equals("id")) {
136
-            String in = console.getStringInput(">> enter id:");
132
+            String in = console.getId();
137 133
             return mySqlDriver.queryId(in);
138 134
 
139 135
         } else if (String.valueOf(input).trim().equals("password")) {
140
-            String in = console.getStringInput(">> enter password:");
136
+            String in = console.getPassword();
141 137
             return mySqlDriver.queryPassword(in);
142 138
 
143 139
         } else if (String.valueOf(input).trim().equals("back")) {
@@ -149,11 +145,10 @@ public class AccountApp {
149 145
     }
150 146
 
151 147
     private int delete() throws SQLException {
152
-        String input = console.getStringInput(">> delete: [ all ] or [ by ]\nor [ back ] to return");
148
+        String input = console.getAllorBy("delete");
153 149
 
154 150
         if (String.valueOf(input).trim().equals("all")) {
155
-            if (console.getStringInput(">> Are you sure you want to delete ALL of the accounts?" +
156
-                            "\n>> anything but [ YES ] will cancel this request").equals("YES"))
151
+            if (console.areYouSure_delete().equals("YES"))
157 152
                 return mySqlDriver.deleteAll(queryAll());
158 153
         } else if (String.valueOf(input).trim().equals("by")) {
159 154
             return deleteBy();
@@ -163,18 +158,18 @@ public class AccountApp {
163 158
     }
164 159
 
165 160
     private int deleteBy() throws SQLException {
166
-        String input = console.getStringInput(">> delete by: [ name ] , [ id ] , or [ password ]\n>> or [ back ] to return");
161
+        String input = console.getBy("delete");
167 162
 
168 163
         if (String.valueOf(input).trim().equals("name")) {
169
-            String in = console.getStringInput(">> enter name:");
164
+            String in = console.getName();
170 165
             return mySqlDriver.deleteName(in);
171 166
 
172 167
         } else if (String.valueOf(input).trim().equals("id")) {
173
-            String in = console.getStringInput(">> enter id:");
168
+            String in = console.getId();
174 169
             return mySqlDriver.deleteId(in);
175 170
 
176 171
         } else if (String.valueOf(input).trim().equals("password")) {
177
-            String in = console.getStringInput(">> enter password:");
172
+            String in = console.getPassword();
178 173
             return mySqlDriver.deletePassword(in);
179 174
 
180 175
         } else if (String.valueOf(input).trim().equals("back")) {

+ 66
- 3
src/main/java/Console.java Parādīt failu

@@ -1,7 +1,11 @@
1 1
 import java.io.InputStream;
2 2
 import java.io.PrintStream;
3
+import java.util.Collections;
4
+import java.util.List;
3 5
 import java.util.Scanner;
4 6
 
7
+import static java.util.Collections.nCopies;
8
+
5 9
 public final class Console {
6 10
     private final Scanner input;
7 11
     private final PrintStream output;
@@ -11,12 +15,12 @@ public final class Console {
11 15
         this.output = out;
12 16
     }
13 17
 
14
-    public String getStringInput(String prompt){
18
+    private String getStringInput(String prompt){
15 19
         System.out.println(prompt);
16 20
         return input.nextLine();
17 21
     }
18 22
 
19
-    public Integer getIntegerInput(String prompt){
23
+    private Integer getIntegerInput(String prompt){
20 24
         try {
21 25
             return Integer.parseInt(getStringInput(prompt));
22 26
         } catch (NumberFormatException n){
@@ -25,11 +29,70 @@ public final class Console {
25 29
         }
26 30
     }
27 31
 
32
+    public void welcome(){
33
+        println("\n:: Welcome to the Account Database ::\n");
34
+    }
35
+
36
+    public String mainMenu(){
37
+        return getStringInput(">> select an option:" + " [ new account ] [ update ] [ query ] [ delete ]\n" +
38
+                ">> or [ quit ] to close program");
39
+    }
40
+
41
+    public String getName(){
42
+        return getStringInput(">> enter name:");
43
+    }
44
+
45
+    public String getId(){
46
+        return getStringInput(">> enter id:");
47
+    }
48
+
49
+    public String getPassword(){
50
+        return getStringInput(">> enter password:");
51
+    }
52
+
53
+    public String getBy(String crudCommand){
54
+        return getStringInput(">> " + crudCommand + " by: [ name ] , [ id ] , or [ password ]\n>> or [ back ] to return");
55
+    }
56
+
57
+    public String getAllorBy(String crudCommand){
58
+        return getStringInput(">> " + crudCommand + ": [ all ] or [ by ]\nor [ back ] to return");
59
+    }
60
+
61
+    public String areYouSure_delete(){
62
+        return getStringInput(">> Are you sure you want to delete ALL of the accounts?" +
63
+                "\n>> anything but [ YES ] will cancel this request");
64
+    }
65
+
28 66
     public void println(String prompt){
29 67
         System.out.println(prompt);
30 68
     }
31 69
 
32 70
     public void print(String prompt){
33
-        System.out.println(prompt);
71
+        System.out.print(prompt);
72
+    }
73
+
74
+    public void returnToMain(){
75
+        println("\n:: main menu ::\n");
76
+    }
77
+
78
+    public void accountDNE(){
79
+        println("\n:: account does not exist ::\n");
80
+    }
81
+
82
+    public void printAccounts(List<Account> accountList){
83
+        String five = "-----";
84
+        String eightn = five + five + five + five + five;
85
+        //header
86
+        println(String.format("\n+ %5s-+-%25s-+-%25s +", five, eightn, eightn));
87
+        println(String.format("| %5s | %25s | %25s |", "ID", "Name", "Password"));
88
+        println(String.format("+ %5s-+-%25s-+-%25s +", five, eightn, eightn));
89
+        //items
90
+        accountList.forEach(e -> println(String.format("| %5s | %25s | %25s |", e.getId(), e.getName(), e.getPassword())));
91
+        //footer
92
+        println(String.format("+ %5s-+-%25s-+-%25s +\n", five, eightn, eightn));
93
+    }
94
+
95
+    public void goodBye(){
96
+        println("[ peace ]");
34 97
     }
35 98
 }

+ 1
- 6
src/main/java/MySqlDriver.java Parādīt failu

@@ -13,16 +13,11 @@ public class MySqlDriver {
13 13
         this.accountDao = accountDao;
14 14
     }
15 15
 
16
-    public Account selectAccount(Integer input) throws Exception{
16
+    public Account selectAccount(String input) throws Exception{
17 17
         QueryBuilder<Account,Integer> qb = accountDao.queryBuilder();
18 18
         qb.where().eq(Account.ID_FIELD_NAME, input);
19 19
         List<Account> list = accountDao.query(qb.prepare());
20
-        //try {
21 20
             return list.get(0);
22
-//        } catch (IndexOutOfBoundsException i) {
23
-//            System.out.println("hey, nothing to see here");
24
-//            return null;
25
-//        }
26 21
     }
27 22
 
28 23
     public int create(Account account) throws SQLException {

Binārs
target/classes/AccountApp.class Parādīt failu


Binārs
target/classes/Console.class Parādīt failu


Binārs
target/classes/MySqlDriver.class Parādīt failu