Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.17 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         User user;
  3.         String opcija;
  4.         Scanner sc = new Scanner(System.in);
  5.         do {
  6.             do {
  7.                 System.out.println("0. Izadjite iz aplikacije");
  8.                 System.out.println("1. Ulogujte se");
  9.                 System.out.println("2. Vidite rang listu ucenika");
  10.                 System.out.println("Unesite redni broj opcije:");
  11.                 opcija = sc.nextLine();
  12.             } while (!Objects.equals(opcija, "0") && !Objects.equals(opcija, "1") && !Objects.equals(opcija, "2"));
  13.             if (Objects.equals(opcija, "0")) {
  14.                 // Izlazak iz aplikacije
  15.                 System.exit(1337);
  16.             } else if (Objects.equals(opcija, "1")) {
  17.                 // Log in
  18.                 boolean isLogged = false;
  19.                 String username, password, pozicija;
  20.                 int counter = 0;
  21.                 do {
  22.                     if (counter == 3) {
  23.                         System.out.println("sry bro");
  24.                         System.exit(1337);
  25.                     }
  26.                     System.out.println("Unesite korisnicko ime: ");
  27.                     username = sc.nextLine();
  28.                     System.out.println("Unesite sifru: ");
  29.                     password = sc.nextLine();
  30.                     user = User.login(username, password);
  31.                     counter++;
  32.                 } while (user == null);
  33.                 isLogged = true;
  34.                 if (Objects.equals(user.getPozicija(), "administrator")){
  35.                     // Administrator
  36.                     do {
  37.                         System.out.println("0. Izlogujte se");
  38.                         System.out.println("1. Dodajte takmicara");
  39.                         System.out.println("2. Dodajte clana komisije");
  40.                         System.out.println("3. Obrisite korisnika");
  41.                         System.out.println("Unesite redni broj opcije:");
  42.                         opcija = sc.nextLine();
  43.                         if (Objects.equals(opcija, "0")){
  44.                             // log out
  45.                             isLogged = false;
  46.                         } else if (Objects.equals(opcija, "1")){
  47.                             // Add takmicar
  48.                             Takmicar newTakmicar = new Takmicar();
  49.                             System.out.println("Unesite ime takmicara:");
  50.                             newTakmicar.setIme(sc.nextLine());
  51.                             System.out.println("Unesite prezime takmicara:");
  52.                             newTakmicar.setPrezime(sc.nextLine());
  53.                             System.out.println("Unesite username takmicara:");
  54.                             newTakmicar.setUsername(sc.nextLine());
  55.                             System.out.println("Unesite sifru takmicara:");
  56.                             newTakmicar.setPassword(sc.nextLine());
  57.                             newTakmicar.addUserToDatabase();
  58.                         } else if (Objects.equals(opcija, "2")){
  59.                             // Add clan komisije
  60.                             Komisija newKomisija = new Komisija();
  61.                             System.out.println("Unesite ime clana komisije:");
  62.                             newKomisija.setIme(sc.nextLine());
  63.                             System.out.println("Unesite prezime clana komisije:");
  64.                             newKomisija.setPrezime(sc.nextLine());
  65.                             System.out.println("Unesite username clana komisije:");
  66.                             newKomisija.setUsername(sc.nextLine());
  67.                             System.out.println("Unesite sifru clana komisije:");
  68.                             newKomisija.setPassword(sc.nextLine());
  69.                             newKomisija.addUserToDatabase();
  70.                         } else if (Objects.equals(opcija, "3")){
  71.                             // Remove user
  72.                             System.out.println("Unesite username korisnika kojeg zelite da obrisete:");
  73.                             //System.out.println(user);
  74.                             ((Administrator) user).removeUserFromDatabase(sc.nextLine());
  75.                         }
  76.                     } while (!Objects.equals(opcija, "0") && !Objects.equals(opcija, "1") && !Objects.equals(opcija, "2") && !Objects.equals(opcija, "3") || isLogged);
  77.                 } else if (Objects.equals(user.getPozicija(), "komisija")){
  78.                     // Komisija
  79.                     do {
  80.                         System.out.println("0. Odjavite se");
  81.                         System.out.println("1. Prikazi spisak radova");
  82.                         System.out.println("2. Oceni rad");
  83.                         System.out.println("Unesite redni broj opcije:");
  84.                         opcija = sc.nextLine();
  85.                         if (Objects.equals(opcija, "0")){
  86.                             // Log out
  87.                             isLogged = false;
  88.                         } else if (Objects.equals(opcija, "1")){
  89.                             // Prikazi spisak radova
  90.                             File file = new File("predatiRadovi");
  91.                             if (file.exists()){
  92.                                 String[] listaRadova = file.list();
  93.                                 for (String rad : listaRadova) {
  94.                                     System.out.println(rad);
  95.                                 }
  96.                             }
  97.                         } else if (Objects.equals(opcija, "2")){
  98.                             // Oceni rad
  99.                             File file = new File("predatiRadovi");
  100.                             if (file.exists()){
  101.                                 int brojRadova = 0;
  102.                                 int izabraniRad = 0;
  103.                                 String[] listaRadova = file.list();
  104.                                 for (String rad : listaRadova) {
  105.                                     brojRadova++;
  106.                                     System.out.println(brojRadova + ". " + rad);
  107.                                 }
  108.                                 if (brojRadova != 0){
  109.                                     do {
  110.                                         System.out.println("Unesite redni broj rada koji zelite da ocenite:");
  111.                                         try{
  112.                                             izabraniRad = sc.nextInt();
  113.                                         } catch (InputMismatchException e){
  114.                                             sc.nextLine();
  115.                                         }
  116.                                     } while (izabraniRad < 1 || izabraniRad > brojRadova);
  117.                                     try {
  118.                                         System.out.println("Sadrzaj rada:\n");
  119.                                         ArrayList<String> lines = (ArrayList<String>) Files.readAllLines(Paths.get("predatiRadovi" + File.separator + listaRadova[izabraniRad-1]), Charset.forName("UTF-8"));
  120.                                         for (String line : lines){
  121.                                             System.out.println(line);
  122.                                         }
  123.                                         int ocena1 = 0, ocena2 = 0, ocena3 = 0;
  124.                                         do {
  125.                                             try {
  126.                                                 System.out.println("Unesite ocenu za kvalitet koda:");
  127.                                                 ocena1 = sc.nextInt();
  128.                                             } catch (InputMismatchException e){
  129.                                                 sc.nextLine();
  130.                                             }
  131.                                         } while (ocena1 < 1 || ocena1 > 10);
  132.                                         do{
  133.                                             try {
  134.                                                 System.out.println("Unesite ocenu za tacnost koda:");
  135.                                                 ocena2 = sc.nextInt();
  136.                                             } catch (InputMismatchException e){
  137.                                                 sc.nextLine();
  138.                                             }
  139.                                         } while (ocena2 < 1 || ocena2 > 10);
  140.                                         do{
  141.                                             try {
  142.                                                 System.out.println("Unesite ocenu opsti utisak: ");
  143.                                                 ocena3 = sc.nextInt();
  144.                                             } catch (InputMismatchException e){
  145.                                                 sc.nextLine();
  146.                                             }
  147.                                         } while (ocena3 < 1 || ocena3 > 10);
  148.                                         ((Komisija) user).oceniRad(listaRadova[izabraniRad-1].split("\\.")[0], "predatiRadovi" + File.separator + listaRadova[izabraniRad-1], ocena1, ocena2, ocena3);
  149.                                         Files.move(Paths.get("predatiRadovi" + File.separator + listaRadova[izabraniRad-1]), Paths.get("pregledaniRadovi" + File.separator + listaRadova[izabraniRad-1]));
  150.                                     } catch (IOException e) {
  151.                                         System.out.println("Doslo je do greske prilikom pomeranja fajla. Da li postoji problem sa permisijama?");
  152.                                         e.printStackTrace();
  153.                                     }
  154.                                 } else {
  155.                                     System.out.println("Svi radovi su ocenjeni.");
  156.                                 }
  157.                             }
  158.                         }
  159.                     } while (!Objects.equals(opcija, "0") && !Objects.equals(opcija, "1") && !Objects.equals(opcija, "2") || isLogged);
  160.                 } else if (Objects.equals(user.getPozicija(), "takmicar")){
  161.                     // Takmicar
  162.                     do {
  163.                         System.out.println("0. Odjavite se");
  164.                         System.out.println("1. Predaj rad");
  165.                         System.out.println("2. Pogledaj status rada");
  166.                         System.out.println("Unesite redni broj opcije:");
  167.                         opcija = sc.nextLine();
  168.                         if (Objects.equals(opcija, "0")) {
  169.                             // Log out
  170.                             isLogged = false;
  171.                         } else if (Objects.equals(opcija, "1")) {
  172.                             // Predaja rada
  173.                             System.out.println("Unesite absolutnu putanju rada: ");
  174.                             String putanja = sc.nextLine();
  175.                             ((Takmicar) user).predajRad(username, putanja);
  176.                         } else if (Objects.equals(opcija, "2")) {
  177.                             // Status rada
  178.                             ((Takmicar) user).statusRada(username);
  179.                         }
  180.                     } while (!Objects.equals(opcija, "0") && !Objects.equals(opcija, "1") && !Objects.equals(opcija, "2") || isLogged);
  181.                 }
  182.             } else {
  183.                 User.rangLista();
  184.             }
  185.         } while (true);
  186.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement