Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package teste;
- import java.util.List;
- import java.util.Scanner;
- import javax.naming.InitialContext;
- import javax.naming.NamingException;
- import data.Professor;
- import data.Student;
- import ejb.adminEJB;
- import ejb.adminEJBRemote;
- public class admin {
- public static void main(String[] args) throws NamingException {
- // TODO Auto-generated method stub
- String user, pass;
- // int op = -1, option = -1;
- Scanner sc = new Scanner(System.in);
- adminEJBRemote ad = (adminEJBRemote) InitialContext
- .doLookup("LearningPlatform-EAR/LearningPlatform_CRUD-EJB/adminEJB!ejb.adminEJBRemote");
- /*
- * System.out.println("Admin Login\n\n"); do {
- * System.out.println("Username:"); user = sc.nextLine();
- * System.out.println("Password:"); pass = sc.nextLine();
- *
- * System.out.println("");
- *
- * } while (!ad.login(user, pass));
- * System.out.println("Login successfull\n\n"); do {
- * System.out.println("1-Add Admin user\n" + "2-Add Professor\n" +
- * "3-Add Student\n" + "4-Add Course\n" + "5-Change info\n" +
- * "6-Delete data\n" + "0-Logout"); op = sc.nextInt();
- *
- * if (op == 1) { createAdmin(); } else if (op == 2) {
- * createProfessor(); } else if (op == 3) { createStudent(); } else if
- * (op == 4) { createCourse(); } else if (op == 5) { do {
- * System.out.println("1-Change Admin info\n" +
- * "2-Change Professor info\n" + "3-Change Student info\n" +
- * "4-Change Course info\n" + "0-Back"); option = sc.nextInt(); if
- * (option == 1) {
- *
- * } else if (option == 2) {
- *
- * } else if (option == 3) {
- *
- * } else if (option == 4) { changeCourse(); } } while (option != 0); }
- * else if (op == 6) {
- *
- * } else if (op == 0) {
- *
- * }
- *
- * } while (op != 0);
- */
- String op;
- System.out.println("##### MENU #####\n");
- do {
- System.out
- .println("1 - Register administrator account\n" + "2 - Delete admistrator account\n" + "3 - Exit");
- op = sc.nextLine();
- // Verifica qual a opção escolhida
- if (op.equals("1")) {
- // Escolheu a opção de registar conta administrador
- createAdmin(ad, sc);
- } else if (op.equals("2")) {
- // Escolheu a opção de eliminar conta administrador
- deleteAdmin(ad, sc);
- }
- } while (!op.equals("3"));
- sc.close();
- }
- public static void createAdmin(adminEJBRemote ad, Scanner sc) {
- String user, pass, passVerification;
- int vf = 0;
- System.out.println("# Create admin account #\n");
- do {
- System.out.println("Username:");
- user = sc.nextLine();
- if (!ad.checkUsername(user)) {
- System.out.println("Username available");
- vf = 0;
- } else {
- System.out.println("Username already in use!");
- vf = 1;
- }
- } while (vf != 0);
- vf = 0;
- do {
- System.out.println("Password:");
- pass = sc.nextLine();
- System.out.println("Repeat Password:");
- passVerification = sc.nextLine();
- if (pass.equals(passVerification)) {
- ad.createAdmin(user, pass);
- vf = 0;
- } else {
- System.out.println("Passwords don't match!");
- vf = 1;
- }
- } while (vf != 0);
- System.out.println("\nAdmin account created with success\n");
- }
- public static void deleteAdmin(adminEJBRemote ad, Scanner sc) {
- String user, user2;
- int vf = 0;
- System.out.println("# Delete admin account #\n");
- do {
- System.out.println("Username:");
- user = sc.nextLine();
- if (!ad.checkUsername(user)) {
- System.out.println("There is not an account with the username: " + user);
- vf = 0;
- } else {
- vf = 1;
- }
- } while (vf == 0);
- vf = 0;
- System.out.println("To confirm the deletion, insert again the username:\nUsername:");
- user2 = sc.nextLine();
- if (!user.equals(user2)) {
- System.out.println("Deletion aborted\n");
- } else {
- ad.deleteAdmin(user);
- System.out.println("\nAdmin account deleted with success\n");
- }
- }
- /*
- *
- * public static void createProfessor() { String name, number, birthdate,
- * email, alternativeEmail, address, phone, internalPhone, salary, office,
- * category; String user, pass, passVer; adminEJBRemote ad = new adminEJB();
- * Scanner sc = new Scanner(System.in); int vf = -1;
- *
- * System.out.println("Name:"); name = sc.nextLine();
- * System.out.println("Internal Number:"); number = sc.nextLine();
- * System.out.println("Birthdate(dd-mm-yyyy):"); birthdate = sc.nextLine();
- * System.out.println("Email:"); email = sc.nextLine();
- * System.out.println("Alternative Email:"); alternativeEmail =
- * sc.nextLine(); System.out.println("Address:"); address = sc.nextLine();
- * System.out.println("Phone:"); phone = sc.nextLine();
- * System.out.println("Internal Phone:"); internalPhone = sc.nextLine();
- * System.out.println("Salary:"); salary = sc.nextLine();
- * System.out.println("Office:"); office = sc.nextLine();
- * System.out.println("Category:"); category = sc.nextLine();
- *
- * do { System.out.println("Username:"); user = sc.nextLine(); if
- * (ad.checkUsername(user)) { System.out.println("Username available"); vf =
- * 0; } else { System.out.println("Username already in use!"); vf = 1; }
- *
- * } while (vf != 0); vf = 0; do { System.out.println("Password:"); pass =
- * sc.nextLine(); System.out.println("Repeat Password:"); passVer =
- * sc.nextLine(); if (pass.equals(passVer)) { vf = 0; } else {
- * System.out.println("Passwords doesn't match!"); vf = 1; } } while (vf !=
- * 0);
- *
- * sc.close(); }
- *
- * public static void createStudent() {
- *
- * String name, number, birthdate, email, alternativeEmail, address, phone,
- * year; String user, pass, passVer; adminEJBRemote ad = new adminEJB();
- * Scanner sc = new Scanner(System.in); int vf = -1;
- *
- * System.out.println("Name:"); name = sc.nextLine();
- * System.out.println("Internal Number:"); number = sc.nextLine();
- * System.out.println("Birthdate(dd-mm-yyyy):"); birthdate = sc.nextLine();
- * System.out.println("Email:"); email = sc.nextLine();
- * System.out.println("Alternative Email:"); alternativeEmail =
- * sc.nextLine(); System.out.println("Address:"); address = sc.nextLine();
- * System.out.println("Phone:"); phone = sc.nextLine();
- * System.out.println("Entry year:"); year = sc.nextLine();
- *
- * do { System.out.println("Username:"); user = sc.nextLine(); if
- * (ad.checkUsername(user)) { System.out.println("Username available"); vf =
- * 0; } else { System.out.println("Username already in use!"); vf = 1; }
- *
- * } while (vf != 0); vf = 0; do { System.out.println("Password:"); pass =
- * sc.nextLine(); System.out.println("Repeat Password:"); passVer =
- * sc.nextLine(); if (pass.equals(passVer)) { vf = 0; } else {
- * System.out.println("Passwords doesn't match!"); vf = 1; } } while (vf !=
- * 0);
- *
- * sc.close();
- *
- * }
- *
- * public static void createCourse() {
- *
- * String name, professor; List<String> students = null; String student;
- * Scanner sc = new Scanner(System.in); int i = 1, vf = -1;
- * System.out.println("Name of the course:"); name = sc.nextLine();
- * System.out.println("Professor in charge:"); professor = sc.nextLine();
- *
- * do { System.out.println("Student " + i + " name:"); student =
- * sc.nextLine(); if (!student.equalsIgnoreCase("Exit")) {
- * students.add(student);
- *
- * i++; } else { vf = 1; } } while (vf != 1);
- *
- * sc.close();
- *
- * }
- *
- * public static void changeCourse() {
- *
- * String courseName; Scanner sc = new Scanner(System.in); int vf=-1;
- * adminEJBRemote ad = new adminEJB();
- *
- * do { System.out.println("Course name:"); courseName = sc.nextLine();
- * if(ad.checkCourse(courseName)){ vf=0; } else{
- * System.out.println("Course not found!"); vf=1; } } while (vf != 0);
- *
- * //mudar o que?? o nome???
- *
- * sc.close(); }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement