Facebook
From Gabi Mateusz, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 281
  1. import java.util.Scanner;
  2.  
  3. public class Parking {
  4.     public static void main(String[] args) {
  5.  
  6.  
  7.         System.out.println("Witaj na parkingu!");
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         String admin;
  11.         String user;
  12.         String password = "";
  13.         int[] places = {0,0,0,1,1,1,0,1,0,1,1,1,1,1};
  14.  
  15.  
  16.         final String staticPassword = "administrator";
  17.  
  18.         System.out.println("Podaj kim jesteś: ");
  19.         user = scanner.nextLine();
  20.         if (user.equals("admin")) {
  21.  
  22.             do {
  23.  
  24.                 System.out.print("Podaj hasło: ");
  25.                 password = scanner.nextLine();
  26.  
  27.             } while (!password.equals("administrator"));
  28.             System.out.println("podałes poprawne hasło");
  29.         }
  30.  
  31.         String response = "";
  32.  
  33.         do {
  34.             if (user.equals("admin")) {
  35.  
  36.                 System.out.println("1 - Pokaz wolne miejsca");
  37.                 System.out.println("2 - Zwolnij wszystkie miejsca parkingowe");
  38.                 System.out.println("3 - Zwolnij jedno miejsce");
  39.             }
  40.  
  41.             System.out.println("4 - Zaparkuj pojazd");
  42.             System.out.println("5 - Odjazd z parkingu");
  43.             System.out.println("6- Zamień miejsce parkingowe");
  44.  
  45.  
  46.             System.out.print("Wybierz opcje: ");
  47.             response = scanner.nextLine();
  48.  
  49.             Scanner placeScanner = new Scanner(System.in);
  50.  
  51.             int placeNumber = 0;
  52.             switch (response) {
  53.                 case "1": {
  54.  
  55.                     int sum = 0;
  56.  
  57.                     for (int i = 0; i < places.length; i++) {
  58.                         if (places[i] == 0) {
  59.                             sum++;
  60.                         }
  61.                     }
  62.                    System.out.println("suma wolnych miejsc to: " + sum);
  63.                     break;
  64.  
  65.                     }
  66.  
  67.                     case "2" : {
  68.                         for (int i= 0; i < places.length; i++){
  69.                             if (places[i] == 1){
  70.                                 places[i] = 0;
  71.                             }
  72.                         }
  73.                         System.out.println("miejsca zostaly zwolnione");
  74.                         break;
  75.  
  76.                     }
  77.  
  78.                 case "3" : {
  79.  
  80.                         System.out.print("Podaj miejsce parkingowe: ");
  81.                         placeNumber = Integer.parseInt(scanner.nextLine());
  82.  
  83.                         if (places[placeNumber] == 0) {
  84.                             System.out.println("To miejsce jest puste!");
  85.                             break;
  86.                         }
  87.                         places [placeNumber] = 0;
  88.  
  89.  
  90.                     System.out.println("miejsce zostało zwolnione!");
  91.                     break;
  92.  
  93.                     }
  94.  
  95.                 case "4" : {
  96.  
  97.                       for (int i=0; i < places.length; i++) {
  98.                           if (places[i] == 0){
  99.                               places[i] = 1;
  100.  
  101.                               System.out.println("Miejsce zostalo zarezerowane");
  102.                               break;
  103.  
  104.                           }
  105.                     }
  106.                     break;
  107.                 }
  108.  
  109.                 case "5" : {
  110.  
  111.                     System.out.print("Podaj miejsce parkingowe: ");
  112.                     placeNumber = Integer.parseInt(scanner.nextLine());
  113.  
  114.                     places [placeNumber] = 0;
  115.  
  116.                     System.out.println("miejsce zostało zwolnione!");
  117.                     break;
  118.  
  119.                 }
  120.  
  121.                 case "6" : {
  122.                     int placeSwitch;
  123.                     System.out.println("Podaj swoje miejsce parkingowe");
  124.                     placeNumber = Integer.parseInt(scanner.nextLine());
  125.  
  126.                     System.out.println("Podaj miejsce zamiany");
  127.                     placeSwitch = Integer.parseInt(scanner.nextLine());
  128.  
  129.  
  130.                         if  (places[placeNumber] == 0 && places[placeSwitch] == 0  ) {
  131.                             System.out.println("Nie mozesz dokonac takiej zmiany");
  132.                         }else  {
  133.                             System.out.println("Miejsce zostalo zwolnione");
  134.                           break;
  135.                     }
  136.                 }
  137.  
  138.  
  139.             }
  140.  
  141.         }
  142.             while (!response.equals("Exit")) ;
  143.  
  144.         }
  145.     }
  146.  
  147.  
  148.