Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. package UnimapDBConsole;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.File;
  6. import java.io.FileReader;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10.  
  11. public class executer
  12. {
  13. BufferedReader reader;
  14. String username;
  15. String password;
  16. int choice;
  17. db dbobject;
  18.  
  19. public executer()
  20. {
  21. reader = new BufferedReader(new InputStreamReader(System.in));
  22. username = password = null;
  23. choice=0;
  24. dbobject = new db();
  25. dbobject.init();
  26. login();
  27. }
  28.  
  29. public void login()
  30. {
  31. while(true)
  32. {
  33.  
  34. try
  35. {
  36. clearScreen();
  37. System.out.println("Welcome!");
  38. System.out.println("Enter Username");
  39. username = reader.readLine();
  40. System.out.println("Enter Password");
  41. password = reader.readLine();
  42. if (dbobject.validate(username, password))
  43. {
  44. menu();
  45. }
  46. else
  47. {
  48. clearScreen();
  49. System.err.println("Authentication Error");
  50. }
  51. //choice = sc.nextInt();
  52. }
  53.  
  54. catch(IOException e)
  55. {
  56. System.err.println("Input / Output error");
  57. }
  58.  
  59. catch(NumberFormatException e)
  60. {
  61. System.err.println("Please enter the correct input");
  62. System.out.println();
  63. menu();
  64. }
  65. }
  66. }
  67.  
  68. public void menu()
  69. {
  70. do
  71. {
  72. clearScreen();
  73. System.out.println("Welcome!");
  74. System.out.println("0. Exit");
  75. System.out.println("1. Add Username");
  76. System.out.println("2. Add Password");
  77. System.out.println("3. Add Full Name");
  78. System.out.println("Please enter your choice: ");
  79.  
  80. try
  81. {
  82. choice = Integer.parseInt(reader.readLine());
  83. //choice = sc.nextInt();
  84.  
  85. if (choice == 0)
  86. {
  87. exit();
  88. }
  89.  
  90. else if (choice == 1)
  91. {
  92. //addUsername();
  93. }
  94.  
  95. else if (choice == 2)
  96. {
  97. //addPassword();
  98. }
  99.  
  100. else if (choice == 2)
  101. {
  102. //addFullname();
  103. }
  104.  
  105. else
  106. {
  107. System.out.println("Invalid choice!");
  108. System.out.println();
  109. }
  110. }
  111.  
  112. catch(IOException e)
  113. {
  114. System.err.println("Input / Output error");
  115. }
  116.  
  117. catch(NumberFormatException e)
  118. {
  119. System.err.println("Please enter the correct input");
  120. System.out.println();
  121. menu();
  122. }
  123. } while(choice != 0);
  124. }
  125.  
  126. public void exit()
  127. {
  128. System.out.println("Program exit!");
  129. }
  130.  
  131. public static void clearScreen()
  132. {
  133. for (int i=1; i<=10; i++)
  134. System.out.println("\n");
  135. }
  136.  
  137. public static void main(String[] args)
  138. {
  139. // TODO Auto-generated method stub
  140. db d = new db();
  141. d.init();
  142. new executer();
  143. }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement