Guest User

Untitled

a guest
Mar 17th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.52 KB | None | 0 0
  1.  
  2. package donorschoose.org;
  3.  
  4. import java.util.Scanner;
  5. import ThankyouPackage.ThankyouPackage;
  6. import Project.*;
  7. import Member.*;
  8. import Member.TeacherList;
  9.  
  10.  
  11.  
  12. /**
  13.  * This is the main class it tests all the behaviors of the implemented classes
  14.  * @version 1.0
  15.  * @author Mounir/ Saad
  16.  * @exception this class throws EnumException which occurs when user inputs invalid enum type, and PassException when user fails to Authenticate
  17.  */
  18. public class DonorsApp {
  19.  
  20.     static int index;
  21.    
  22.     public static void main(String[] args) {
  23.        
  24.         Scanner input = new Scanner(System.in);
  25.  
  26.          UserList users = new UserList();
  27.          TeacherList teachers = new TeacherList();
  28.  
  29.  
  30.         int choice;
  31.         int flag = 0;
  32.         int flag2 = 0;
  33.         int initialpts =0;
  34.  
  35.  
  36.  
  37.          do{
  38.  
  39.              System.out.println("----------------------------------------------");
  40.              System.out.println("   Hello user. Please choose an option");
  41.              System.out.println("   1. Register");
  42.              System.out.println("   2. Exit");
  43.              System.out.println("---------------------------------------------");
  44.              System.out.print("       Choice:");
  45.              choice = input.nextInt();
  46.  
  47.              switch (choice){
  48.                  case 1:
  49.                      System.out.println("---------------------------------------------");
  50.                      System.out.println("   Please choose your option for Registration");
  51.                      System.out.println("   1. Register as a Teacher");
  52.                      System.out.println("   2. Register as a User   ");
  53.                      System.out.println("---------------------------------------------");
  54.                      System.out.print("       Choice:");
  55.                      choice = input.nextInt();
  56.                      switch (choice){
  57.                          case 1:
  58.                              System.out.println(" Registering as a Teacher !");
  59.                              System.out.println(" Enter Username");
  60.                              String t_username = input.next();
  61.                              System.out.println(" Enter Password");
  62.                              String t_pswd = input.next();
  63.                              System.out.println(" Enter First Name");
  64.                              String t_f_name = input.next();
  65.                              System.out.println(" Enter Last Name");
  66.                              String t_l_name = input.next();
  67.                              System.out.println(" Enter Email ");
  68.                              String t_mail = input.next();
  69.                              String t_position= "huhu";
  70.                              int t_pts=initialpts;
  71.  
  72.                              Teacher t1 = new Teacher(t_username, t_pswd, t_f_name, t_l_name, t_mail, t_position, t_pts);
  73.  
  74.                              teachers.addTeacher(t1);
  75.                              break;// Break registration as a teacher
  76.  
  77.                          case 2:
  78.                              System.out.println(" Registering as a User !");
  79.                              System.out.println(" Enter Username");
  80.                              String u_username = input.next();
  81.                              System.out.println(" Enter Password");
  82.                              String u_pswd = input.next();
  83.                              System.out.println(" Enter First Name");
  84.                              String u_f_name = input.next();
  85.                              System.out.println(" Enter Last Name");
  86.                              String u_l_name = input.next();
  87.                              System.out.println(" Enter Email ");
  88.                              String u_mail = input.next();
  89.  
  90.                              User u1 =new User(u_username, u_pswd, u_f_name, u_l_name, u_mail);
  91.  
  92.                              users.addUser(u1);
  93.                              break;//Break registration as a user
  94.  
  95.                      }
  96.                  flag =1;
  97.                  break;// Break registration
  98.  
  99.                  case 2:
  100.                  flag=1;
  101.                  break;// exit the program
  102.                  default:
  103.                      System.out.println("Invalid choice! Please Try Again!");
  104.                  break;
  105.  
  106.              }
  107.          }while(flag!=1);
  108.  
  109.         //First time run handeled
  110.  
  111.         flag = choice = 0;
  112.  
  113.         do{
  114.              System.out.println("---------------------------------------");
  115.              System.out.println("   1. Login");
  116.              System.out.println("   2. Register");
  117.              System.out.println("   3. Exit");
  118.              System.out.println("---------------------------------------");
  119.              System.out.print("         Choice:");
  120.              choice = input.nextInt();
  121.  
  122.              switch (choice){
  123.                  case 1:
  124.  
  125.                      String user;
  126.                      String pswd;
  127.                      do{
  128.                      System.out.print("AUTHENTICATION !");
  129.                      System.out.print("Enter UserName");
  130.                      user = input.next();
  131.                      System.out.print("Enter Password: ");
  132.                      pswd = input.next();
  133.  
  134.  
  135.  
  136.                      index = users.search(user);
  137.  
  138.  
  139.                      if (index == -1)
  140.                          System.out.println("Login Error!");
  141.  
  142.  
  143.  
  144.                      }while( index == -1);
  145.  
  146.  
  147.                      try{
  148.  
  149.                          if(teachers.getTeacher(index).Authenticate(user, pswd)){
  150.                                 System.out.println("Authentification Successful!\n\n");
  151.                          }
  152.                          else
  153.                                throw new PassException();
  154.                      }catch(PassException ex){
  155.                        System.out.println(ex.getMessage());
  156.                       }
  157.  
  158.                  break; //Break case Login
  159.  
  160.                  case 2:
  161.  
  162.                      System.out.println("---------------------------------------------");
  163.                      System.out.println("   Please choose your option for Registration");
  164.                      System.out.println("   1. Register as a Teacher");
  165.                      System.out.println("   2. Register as a User   ");
  166.                      System.out.println("---------------------------------------------");
  167.                      System.out.print("       Choice:");
  168.                      choice = input.nextInt();
  169.                      switch (choice){
  170.                          case 1:
  171.                              System.out.println(" Registering as a Teacher !");
  172.                              System.out.println(" Enter Username");
  173.                              String t_username = input.next();
  174.                              System.out.println(" Enter Password");
  175.                              String t_pswd = input.next();
  176.                              System.out.println(" Enter First Name");
  177.                              String t_f_name = input.next();
  178.                              System.out.println(" Enter Last Name");
  179.                              String t_l_name = input.next();
  180.                              System.out.println(" Enter Email ");
  181.                              String t_mail = input.next();
  182.                              String t_position= "huhu";
  183.                              int t_pts=initialpts;
  184.  
  185.                              Teacher t1 = new Teacher(t_username, t_pswd, t_f_name, t_l_name, t_mail, t_position, t_pts);
  186.  
  187.                              teachers.addTeacher(t1);
  188.                              break;// Break registration as a teacher
  189.  
  190.                          case 2:
  191.                              System.out.println(" Registering as a User !");
  192.                              System.out.println(" Enter Username");
  193.                              String u_username = input.next();
  194.                              System.out.println(" Enter Password");
  195.                              String u_pswd = input.next();
  196.                              System.out.println(" Enter First Name");
  197.                              String u_f_name = input.next();
  198.                              System.out.println(" Enter Last Name");
  199.                              String u_l_name = input.next();
  200.                              System.out.println(" Enter Email ");
  201.                              String u_mail = input.next();
  202.  
  203.                              User u1 =new User(u_username, u_pswd, u_f_name, u_l_name, u_mail);
  204.  
  205.                              users.addUser(u1);
  206.                              break;//Break registration as a user
  207.  
  208.                      }
  209.                  flag =1;
  210.                  break; //Break case Register
  211.  
  212.                  case 3:
  213.                   flag =1;
  214.                  break;// Exit
  215.                  default:
  216.                      System.out.println("Invalid choice! Please Try Again!");
  217.                  break;
  218.              }
  219.         /*
  220.          * Ha fin Wselt le rest tkharbik pour le moment
  221.          * */
  222.         System.out.println("---------------------------------");
  223.         System.out.println("Menu");
  224.         System.out.println("-------------Choose a scenario--------------------");
  225.         System.out.println("Teacher Scenarios:  \n");
  226.         System.out.println("---------------------------------");
  227.         System.out.println("\t *1. Register to become a teacher ");
  228.         System.out.println("\t *2. Login");
  229.         System.out.println("\t *3. Modify profile and personal information");
  230.         System.out.println("\t *4. Create a project, add the different details and the material list");
  231.         System.out.println("\t *5. View donations");
  232.         System.out.println("\t *6. Post a thank you package");
  233.         System.out.println("---------------------------------");
  234.         System.out.println("User scenarios:     \n");
  235.         System.out.println("---------------------------------");
  236.         System.out.println("\t *7. Register as a normal user");
  237.         System.out.println("\t *8. Login");
  238.         System.out.println("\t *9. Browse for projects");
  239.         System.out.println("\t *10. Add projects to the whishlist");
  240.         System.out.println("\t *11. Choose a project, Post a message");
  241.         System.out.println("\t *12. Choose a project from the whishlist, Donate to the project");
  242.         System.out.println("\t *13. Display the donation history");
  243.         System.out.println("\t *14. EXIT");
  244.         System.out.println("---------------------------------");
  245.  
  246.              choice = input.nextInt();
  247.  
  248.         switch (choice){
  249.             case 1:
  250.                
  251.         }
  252.          }while(flag==0);
  253.     }
  254.  }
Add Comment
Please, Sign In to add comment