- import java.util.Scanner;
- public class Parking {
- public static void main(String[] args) {
- System.out.println("Witaj na parkingu!");
- Scanner scanner = new Scanner(System.in);
- String admin;
- String user;
- String password = "";
- int[] places = {0,0,0,1,1,1,0,1,0,1,1,1,1,1};
- final String staticPassword = "administrator";
- System.out.println("Podaj kim jesteś: ");
- user = scanner.nextLine();
- if (user.equals("admin")) {
- do {
- System.out.print("Podaj hasło: ");
- password = scanner.nextLine();
- } while (!password.equals("administrator"));
- System.out.println("podałes poprawne hasło");
- }
- String response = "";
- do {
- if (user.equals("admin")) {
- System.out.println("1 - Pokaz wolne miejsca");
- System.out.println("2 - Zwolnij wszystkie miejsca parkingowe");
- System.out.println("3 - Zwolnij jedno miejsce");
- }
- System.out.println("4 - Zaparkuj pojazd");
- System.out.println("5 - Odjazd z parkingu");
- System.out.println("6- Zamień miejsce parkingowe");
- System.out.print("Wybierz opcje: ");
- response = scanner.nextLine();
- Scanner placeScanner = new Scanner(System.in);
- int placeNumber = 0;
- switch (response) {
- case "1": {
- int sum = 0;
- for (int i = 0; i < places.length; i++) {
- if (places[i] == 0) {
- sum++;
- }
- }
- System.out.println("suma wolnych miejsc to: " + sum);
- break;
- }
- case "2" : {
- for (int i= 0; i < places.length; i++){
- if (places[i] == 1){
- places[i] = 0;
- }
- }
- System.out.println("miejsca zostaly zwolnione");
- break;
- }
- case "3" : {
- System.out.print("Podaj miejsce parkingowe: ");
- placeNumber = Integer.parseInt(scanner.nextLine());
- if (places[placeNumber] == 0) {
- System.out.println("To miejsce jest puste!");
- break;
- }
- places [placeNumber] = 0;
- System.out.println("miejsce zostało zwolnione!");
- break;
- }
- case "4" : {
- for (int i=0; i < places.length; i++) {
- if (places[i] == 0){
- places[i] = 1;
- System.out.println("Miejsce zostalo zarezerowane");
- break;
- }
- }
- break;
- }
- case "5" : {
- System.out.print("Podaj miejsce parkingowe: ");
- placeNumber = Integer.parseInt(scanner.nextLine());
- places [placeNumber] = 0;
- System.out.println("miejsce zostało zwolnione!");
- break;
- }
- case "6" : {
- int placeSwitch;
- System.out.println("Podaj swoje miejsce parkingowe");
- placeNumber = Integer.parseInt(scanner.nextLine());
- System.out.println("Podaj miejsce zamiany");
- placeSwitch = Integer.parseInt(scanner.nextLine());
- if (places[placeNumber] == 0 && places[placeSwitch] == 0 ) {
- System.out.println("Nie mozesz dokonac takiej zmiany");
- }else {
- System.out.println("Miejsce zostalo zwolnione");
- break;
- }
- }
- }
- }
- while (!response.equals("Exit")) ;
- }
- }