214 lines
6.0 KiB
Java
214 lines
6.0 KiB
Java
package autovermietung.helper;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.sql.Date;
|
|
|
|
public final class Tastatur {
|
|
private static BufferedReader b = null;
|
|
private static Exception fehler = null;
|
|
private static boolean einfacheFehlerbehandlung = true;
|
|
|
|
public Tastatur() {
|
|
}
|
|
|
|
private static void Tastatur() {
|
|
if (b == null) {
|
|
b = new BufferedReader(new InputStreamReader(System.in));
|
|
}
|
|
|
|
fehler = null;
|
|
}
|
|
|
|
public static Exception getFehler() {
|
|
return fehler;
|
|
}
|
|
|
|
public static String getFehlerMeldung() {
|
|
return fehler != null ? fehler.toString() : "";
|
|
}
|
|
|
|
public static boolean istFehlerAufgetreten() {
|
|
return fehler != null;
|
|
}
|
|
|
|
public static void setEinfacheFehlerbehandlung(boolean ein) {
|
|
einfacheFehlerbehandlung = ein;
|
|
fehler = null;
|
|
}
|
|
|
|
public static boolean istEinfacheFehlerbehandlung() {
|
|
return einfacheFehlerbehandlung;
|
|
}
|
|
|
|
public static byte liesByte() {
|
|
while(true) {
|
|
try {
|
|
return Byte.parseByte(liesString());
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return 0;
|
|
}
|
|
|
|
System.out.println("Dies ist kein gueltiger Byte-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static short liesShort() {
|
|
while(true) {
|
|
try {
|
|
return Short.parseShort(liesString());
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return 0;
|
|
}
|
|
|
|
System.out.println("Dies ist kein gueltiger Short-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int liesInt() {
|
|
while(true) {
|
|
try {
|
|
return Integer.parseInt(liesString(), 10);
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return 0;
|
|
}
|
|
|
|
System.out.println("Dies ist kein gueltiger Integer-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static char liesChar() {
|
|
while(true) {
|
|
try {
|
|
return liesString().charAt(0);
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return '\u0000';
|
|
}
|
|
|
|
System.out.println("Das ist kein gueltiges Zeichen. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static long liesLong() {
|
|
while(true) {
|
|
try {
|
|
fehler = null;
|
|
return Long.parseLong(liesString(), 10);
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return 0L;
|
|
}
|
|
|
|
System.out.println("Dies ist kein gueltiger Long-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Date liesDate() {
|
|
while(true) {
|
|
try {
|
|
fehler = null;
|
|
return Date.valueOf(liesString());
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return Date.valueOf("2020-12-12");
|
|
}
|
|
|
|
System.out.println("Dies ist kein gueltiger Date-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static boolean liesBoolean() {
|
|
while(true) {
|
|
try {
|
|
fehler = null;
|
|
String s = liesString();
|
|
if (s.toUpperCase().charAt(0) != 'J' && s.toUpperCase().charAt(0) != 'Y' && s.toUpperCase().charAt(0) != 'T' && s.toUpperCase().charAt(0) != '1') {
|
|
if (s.toUpperCase().charAt(0) == 'N') {
|
|
return false;
|
|
}
|
|
|
|
return Boolean.valueOf(s);
|
|
}
|
|
|
|
return true;
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return false;
|
|
}
|
|
|
|
System.out.println("Das ist kein gueltiger boolean-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static double liesDouble() {
|
|
while(true) {
|
|
try {
|
|
fehler = null;
|
|
return Double.parseDouble(liesString());
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return 0.0D;
|
|
}
|
|
|
|
System.out.println("Das ist kein gueltiger Double-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static float liesFloat() {
|
|
while(true) {
|
|
try {
|
|
fehler = null;
|
|
return Float.parseFloat(liesString());
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return 0.0F;
|
|
}
|
|
|
|
System.out.println("Das ist kein gueltiger float-Wert. Bitte Eingabe wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static String liesString() {
|
|
Tastatur();
|
|
|
|
while(true) {
|
|
try {
|
|
return b.readLine();
|
|
} catch (Exception var1) {
|
|
fehler = var1;
|
|
if (!einfacheFehlerbehandlung) {
|
|
return "";
|
|
}
|
|
|
|
System.out.println("Bei der Eingabe ist ein Fehler aufgetreten. Bitte wiederholen!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void loescheFehler() {
|
|
fehler = null;
|
|
}
|
|
}
|