Anzahleingabe optimiert

This commit is contained in:
Joel Baldauf
2020-12-15 13:32:59 +01:00
parent 5cad96d6d5
commit 1131f0ab5a
+8 -6
View File
@@ -11,14 +11,16 @@ class Fahrkartenautomat
System.out.print("Ticketpreis (EURO): "); System.out.print("Ticketpreis (EURO): ");
zuZahlenderBetrag = tastatur.nextDouble(); zuZahlenderBetrag = tastatur.nextDouble();
System.out.print("Anzahl der Tickets: "); while (true) {
anzahlTickets = tastatur.nextByte(); System.out.print("Anzahl der Tickets: ");
anzahlTickets = tastatur.nextByte();
while (!(anzahlTickets > 0 && anzahlTickets <= 10)) { if (!(anzahlTickets > 0 && anzahlTickets <= 10)) {
System.out.print("Es wurde ein ungültiger Wert für die Ticketanzahl eingegeben. \n" System.out.print("Es wurde ein ungültiger Wert für die Ticketanzahl eingegeben. \n"
+ "Bitte erneut versuchen.\n" + "Bitte erneut versuchen.\n"
+ "Anzahl der Tickets: "); + "Anzahl der Tickets: ");
anzahlTickets = tastatur.nextByte(); continue;
}
break;
} }
zuZahlenderBetrag = anzahlTickets * zuZahlenderBetrag; zuZahlenderBetrag = anzahlTickets * zuZahlenderBetrag;