Узнать, свободен ли указанный c таймфрейм в массиве - PullRequest
0 голосов
/ 05 мая 2020

Этот проект «аэроклуба» предназначен для того, чтобы помочь сотрудникам летного клуба управлять своей работой, поэтому есть несколько методов для достижения этой цели и сделать это. Тем не менее, я java-младший и не очень хорошо знаком с гибкостью java и его функциями, когда дело доходит до немного более сложных задач, таких как следующая: этот метод должен проверять, свободен ли какой-либо рейс в определенном c временные рамки (предоставленные пользователем) и распечатайте тех, кто есть на самом деле, и если таковых нет, его следует распечатать (к сожалению, на этот временной интервал нет никого, который можно было бы забронировать). Я пробовал несколькими способами и разными методами, но ни один из них не работает:

Метод:

public static void rentFlight(int[] flightQuantity, String[] identification, String[] time, int index, boolean free) throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("Which flight would you like to rent (enter the number of it)");
        index = sc.nextInt();
        System.out.println("For when are you renting the flight: (hh:mm)");
        String z = sc.nextLine(); // time frame given
        for (int i = 0; i < time.length; i++) { // iterate through the time array 
            if (!z.contains(String.valueOf(time))) { // if the time given doesn't match in any way, then the flight is free
                System.out.println("The flight is free and can be rented: " + identification[i]);
            } else {
                System.out.println("There is unfortunately no free flights");
                break;
            }
        }
    }

метод, в котором параметры заполняются вводом от пользователя:

public static void rentAll(int[] flightQuantity, String[] identification, String[] time, String[] name, String[] surname, int index, boolean free) throws ParseException {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < flightQuantity.length; i++) {
            System.out.println("flight number: " + flugAnzahl[i]);
            index++;
            System.out.println("flight description: " + bezeichnung[i]);
            System.out.println("At which time would you like to rent the flight");
            System.out.println("enter the time as following: (hh:mm)");
            time[i] = sc.nextLine();
            SimpleDateFormat ft = new SimpleDateFormat("hh:mm");
            Date time2 = ft.parse(time[i]);
            System.out.println(ft.format(time2));
            Date dJetzt = new Date();
            System.out.println("the time now is: " + ft.format(dJetzt));
            System.out.println("the name of the person: ");
            name[i + 1] = sc.nextLine();
            System.out.println("the surname of the person ");
            surname[i + 1] = sc.nextLine();
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...