Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. package teste;
  2.  
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. import javax.naming.InitialContext;
  7. import javax.naming.NamingException;
  8.  
  9. import data.Professor;
  10. import data.Student;
  11. import ejb.adminEJB;
  12. import ejb.adminEJBRemote;
  13.  
  14. public class admin {
  15.  
  16. public static void main(String[] args) throws NamingException {
  17. // TODO Auto-generated method stub
  18. String user, pass;
  19. // int op = -1, option = -1;
  20.  
  21. Scanner sc = new Scanner(System.in);
  22. adminEJBRemote ad = (adminEJBRemote) InitialContext
  23. .doLookup("LearningPlatform-EAR/LearningPlatform_CRUD-EJB/adminEJB!ejb.adminEJBRemote");
  24.  
  25. /*
  26. * System.out.println("Admin Login\n\n"); do {
  27. * System.out.println("Username:"); user = sc.nextLine();
  28. * System.out.println("Password:"); pass = sc.nextLine();
  29. *
  30. * System.out.println("");
  31. *
  32. * } while (!ad.login(user, pass));
  33. * System.out.println("Login successfull\n\n"); do {
  34. * System.out.println("1-Add Admin user\n" + "2-Add Professor\n" +
  35. * "3-Add Student\n" + "4-Add Course\n" + "5-Change info\n" +
  36. * "6-Delete data\n" + "0-Logout"); op = sc.nextInt();
  37. *
  38. * if (op == 1) { createAdmin(); } else if (op == 2) {
  39. * createProfessor(); } else if (op == 3) { createStudent(); } else if
  40. * (op == 4) { createCourse(); } else if (op == 5) { do {
  41. * System.out.println("1-Change Admin info\n" +
  42. * "2-Change Professor info\n" + "3-Change Student info\n" +
  43. * "4-Change Course info\n" + "0-Back"); option = sc.nextInt(); if
  44. * (option == 1) {
  45. *
  46. * } else if (option == 2) {
  47. *
  48. * } else if (option == 3) {
  49. *
  50. * } else if (option == 4) { changeCourse(); } } while (option != 0); }
  51. * else if (op == 6) {
  52. *
  53. * } else if (op == 0) {
  54. *
  55. * }
  56. *
  57. * } while (op != 0);
  58. */
  59.  
  60. String op;
  61.  
  62. System.out.println("##### MENU #####\n");
  63.  
  64. do {
  65. System.out
  66. .println("1 - Register administrator account\n" + "2 - Delete admistrator account\n" + "3 - Exit");
  67.  
  68. op = sc.nextLine();
  69.  
  70. // Verifica qual a opção escolhida
  71. if (op.equals("1")) {
  72. // Escolheu a opção de registar conta administrador
  73.  
  74. createAdmin(ad, sc);
  75. } else if (op.equals("2")) {
  76. // Escolheu a opção de eliminar conta administrador
  77.  
  78. deleteAdmin(ad, sc);
  79. }
  80.  
  81. } while (!op.equals("3"));
  82.  
  83. sc.close();
  84. }
  85.  
  86. public static void createAdmin(adminEJBRemote ad, Scanner sc) {
  87. String user, pass, passVerification;
  88. int vf = 0;
  89.  
  90. System.out.println("# Create admin account #\n");
  91.  
  92. do {
  93. System.out.println("Username:");
  94. user = sc.nextLine();
  95.  
  96. if (!ad.checkUsername(user)) {
  97. System.out.println("Username available");
  98. vf = 0;
  99.  
  100. } else {
  101. System.out.println("Username already in use!");
  102. vf = 1;
  103. }
  104.  
  105. } while (vf != 0);
  106. vf = 0;
  107.  
  108. do {
  109. System.out.println("Password:");
  110. pass = sc.nextLine();
  111.  
  112. System.out.println("Repeat Password:");
  113. passVerification = sc.nextLine();
  114.  
  115. if (pass.equals(passVerification)) {
  116.  
  117. ad.createAdmin(user, pass);
  118. vf = 0;
  119.  
  120. } else {
  121. System.out.println("Passwords don't match!");
  122. vf = 1;
  123. }
  124. } while (vf != 0);
  125.  
  126. System.out.println("\nAdmin account created with success\n");
  127. }
  128.  
  129. public static void deleteAdmin(adminEJBRemote ad, Scanner sc) {
  130. String user, user2;
  131. int vf = 0;
  132.  
  133. System.out.println("# Delete admin account #\n");
  134.  
  135. do {
  136. System.out.println("Username:");
  137. user = sc.nextLine();
  138.  
  139. if (!ad.checkUsername(user)) {
  140. System.out.println("There is not an account with the username: " + user);
  141. vf = 0;
  142.  
  143. } else {
  144. vf = 1;
  145. }
  146.  
  147. } while (vf == 0);
  148. vf = 0;
  149.  
  150. System.out.println("To confirm the deletion, insert again the username:\nUsername:");
  151. user2 = sc.nextLine();
  152.  
  153. if (!user.equals(user2)) {
  154. System.out.println("Deletion aborted\n");
  155.  
  156. } else {
  157. ad.deleteAdmin(user);
  158.  
  159. System.out.println("\nAdmin account deleted with success\n");
  160. }
  161.  
  162. }
  163.  
  164. /*
  165. *
  166. * public static void createProfessor() { String name, number, birthdate,
  167. * email, alternativeEmail, address, phone, internalPhone, salary, office,
  168. * category; String user, pass, passVer; adminEJBRemote ad = new adminEJB();
  169. * Scanner sc = new Scanner(System.in); int vf = -1;
  170. *
  171. * System.out.println("Name:"); name = sc.nextLine();
  172. * System.out.println("Internal Number:"); number = sc.nextLine();
  173. * System.out.println("Birthdate(dd-mm-yyyy):"); birthdate = sc.nextLine();
  174. * System.out.println("Email:"); email = sc.nextLine();
  175. * System.out.println("Alternative Email:"); alternativeEmail =
  176. * sc.nextLine(); System.out.println("Address:"); address = sc.nextLine();
  177. * System.out.println("Phone:"); phone = sc.nextLine();
  178. * System.out.println("Internal Phone:"); internalPhone = sc.nextLine();
  179. * System.out.println("Salary:"); salary = sc.nextLine();
  180. * System.out.println("Office:"); office = sc.nextLine();
  181. * System.out.println("Category:"); category = sc.nextLine();
  182. *
  183. * do { System.out.println("Username:"); user = sc.nextLine(); if
  184. * (ad.checkUsername(user)) { System.out.println("Username available"); vf =
  185. * 0; } else { System.out.println("Username already in use!"); vf = 1; }
  186. *
  187. * } while (vf != 0); vf = 0; do { System.out.println("Password:"); pass =
  188. * sc.nextLine(); System.out.println("Repeat Password:"); passVer =
  189. * sc.nextLine(); if (pass.equals(passVer)) { vf = 0; } else {
  190. * System.out.println("Passwords doesn't match!"); vf = 1; } } while (vf !=
  191. * 0);
  192. *
  193. * sc.close(); }
  194. *
  195. * public static void createStudent() {
  196. *
  197. * String name, number, birthdate, email, alternativeEmail, address, phone,
  198. * year; String user, pass, passVer; adminEJBRemote ad = new adminEJB();
  199. * Scanner sc = new Scanner(System.in); int vf = -1;
  200. *
  201. * System.out.println("Name:"); name = sc.nextLine();
  202. * System.out.println("Internal Number:"); number = sc.nextLine();
  203. * System.out.println("Birthdate(dd-mm-yyyy):"); birthdate = sc.nextLine();
  204. * System.out.println("Email:"); email = sc.nextLine();
  205. * System.out.println("Alternative Email:"); alternativeEmail =
  206. * sc.nextLine(); System.out.println("Address:"); address = sc.nextLine();
  207. * System.out.println("Phone:"); phone = sc.nextLine();
  208. * System.out.println("Entry year:"); year = sc.nextLine();
  209. *
  210. * do { System.out.println("Username:"); user = sc.nextLine(); if
  211. * (ad.checkUsername(user)) { System.out.println("Username available"); vf =
  212. * 0; } else { System.out.println("Username already in use!"); vf = 1; }
  213. *
  214. * } while (vf != 0); vf = 0; do { System.out.println("Password:"); pass =
  215. * sc.nextLine(); System.out.println("Repeat Password:"); passVer =
  216. * sc.nextLine(); if (pass.equals(passVer)) { vf = 0; } else {
  217. * System.out.println("Passwords doesn't match!"); vf = 1; } } while (vf !=
  218. * 0);
  219. *
  220. * sc.close();
  221. *
  222. * }
  223. *
  224. * public static void createCourse() {
  225. *
  226. * String name, professor; List<String> students = null; String student;
  227. * Scanner sc = new Scanner(System.in); int i = 1, vf = -1;
  228. * System.out.println("Name of the course:"); name = sc.nextLine();
  229. * System.out.println("Professor in charge:"); professor = sc.nextLine();
  230. *
  231. * do { System.out.println("Student " + i + " name:"); student =
  232. * sc.nextLine(); if (!student.equalsIgnoreCase("Exit")) {
  233. * students.add(student);
  234. *
  235. * i++; } else { vf = 1; } } while (vf != 1);
  236. *
  237. * sc.close();
  238. *
  239. * }
  240. *
  241. * public static void changeCourse() {
  242. *
  243. * String courseName; Scanner sc = new Scanner(System.in); int vf=-1;
  244. * adminEJBRemote ad = new adminEJB();
  245. *
  246. * do { System.out.println("Course name:"); courseName = sc.nextLine();
  247. * if(ad.checkCourse(courseName)){ vf=0; } else{
  248. * System.out.println("Course not found!"); vf=1; } } while (vf != 0);
  249. *
  250. * //mudar o que?? o nome???
  251. *
  252. * sc.close(); }
  253. */
  254.  
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement