first draft + methode für eingabe

main
Eric Paci 2024-05-14 22:27:03 +02:00
parent 09d7536d36
commit f47b3a3ed7
1 changed files with 12 additions and 13 deletions

View File

@ -7,6 +7,16 @@ public class Schachbrett {
public Schachbrett() {
felder = new String[][] {{"A","B","C","D","E","F","G","H"},{"1","2","3","4","5","6","7","8"}};
}
public static int gueltigeEingabe(Scanner in, String achse) {
int zahl = 0;
do {
System.out.println("Position auf " + achse + " Achse: ");
zahl = in.nextInt();
} while (istEingabeUngueltig(zahl));
return zahl;
}
public static boolean istEingabeUngueltig(int Zahl) {
@ -26,19 +36,8 @@ public class Schachbrett {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = 0;
int y = 0;
do {
System.out.println("Position auf x Achse: ");
x = in.nextInt();
} while (istEingabeUngueltig(x));
do {
System.out.println("Position auf y Achse: ");
y = in.nextInt();
} while (istEingabeUngueltig(y));
int x = gueltigeEingabe(in, "x");
int y = gueltigeEingabe(in, "y");
in.close();
Schachbrett instanz = new Schachbrett();