Попытка сделать al oop, который запрашивает исправление, когда добавлено неправильное значение - PullRequest
0 голосов
/ 22 апреля 2020

Я пытаюсь сделать так, чтобы, если было введено значение меньше 50 (LOWEST_ORDER_PRICE), l oop запросит правильную сумму или продолжит, прямо сейчас это просто застревает .. какое-нибудь посещение?

package controller;

import java.util.Scanner;

public class GoedGoedLauncher {
    final static double LOWEST_ORDER_PRICE = 50.0;

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        // 1- prompt the user to input their name and how many orders
        System.out.println("Dit programma is gemaakt door Adzor Verhaagen, MIW - Cohort20, ");
        System.out.print("Voor welke klant wil he de categorie bepalen? ");
        input.nextLine();
        System.out.print("Hoeveel bestellingen moeten er worden ingevoerd? ");
        int numberBestellings = input.nextInt();
        input.nextLine();
        System.out.println();
        //2- make three arrays to hold the bestellingskenmerken(String), totaaledrag (double), bonuspunten(int)
        String[] bestellingsKenmerken = new String[numberBestellings];
        double[] totaalBedrag = new double[numberBestellings];
        int [] bonusPunten = new int[numberBestellings];
        // 3- ask the user for the bestellingskenmerken(int), totaaledrag (double)(not less than 50.0)
        for (int i = 0; i < numberBestellings; i++) {
            System.out.println("Bestelling " + (i + 1));
            System.out.print("\tGeef het kenmerk van de bestelling: ");
            bestellingsKenmerken[i] = input.nextLine();
            do {
                System.out.print("\tGeef het totaalbedrag: ");
                totaalBedrag[i] = input.nextInt();
                input.nextDouble();
                if (totaalBedrag[i] < LOWEST_ORDER_PRICE) {
                    System.out.print("\tFoute invoer! Geef een bedrag van minimaal" + LOWEST_ORDER_PRICE + "euro!\n");
                    System.out.print("\tGeef het totaalbedrag: ");
                    totaalBedrag[i] = input.nextInt();
                }
            } while (totaalBedrag[i] > LOWEST_ORDER_PRICE);
        }
    }
}

1 Ответ

0 голосов
/ 22 апреля 2020

Проблема в состоянии "do-while" es c. Вы можете попробовать это:

do {
       System.out.print("\tGeef het totaalbedrag: ");
       totaalBedrag[i] = input.nextInt();
       // Useless row: input.nextDouble();
       if (totaalBedrag[i] < LOWEST_ORDER_PRICE)
            System.out.print("\tFoute invoer! Geef een bedrag van minimaal" + LOWEST_ORDER_PRICE + "euro!\n");

} while (totaalBedrag[i] < LOWEST_ORDER_PRICE);
...