unnötige Sachen entfernt
parent
96ce02d1f3
commit
9404b01c9a
|
@ -1,5 +1,3 @@
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Schachbrett {
|
public class Schachbrett {
|
||||||
//bauen eines schachbretts Feldname(0,0) -> "A1"
|
//bauen eines schachbretts Feldname(0,0) -> "A1"
|
||||||
private String[][] felder;
|
private String[][] felder;
|
||||||
|
@ -8,40 +6,17 @@ public class Schachbrett {
|
||||||
felder = new String[][] {{"A","B","C","D","E","F","G","H"},{"1","2","3","4","5","6","7","8"}};
|
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) {
|
|
||||||
if (Zahl < 1 || Zahl > 8) {
|
|
||||||
System.out.println("Falsche Eingabe, bitte gib eine Zahl zwischen 1 und 8 ein.");
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} else return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String feldname(int row, int col) {
|
public String feldname(int row, int col) {
|
||||||
String Ergebnis = felder[0][col] + felder[1][row];
|
String Ergebnis = felder[0][col] + felder[1][row];
|
||||||
|
//System.out.println("Die Position auf dem Schachbrett ist: " + Ergebnis);
|
||||||
return Ergebnis;
|
return Ergebnis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner in = new Scanner(System.in);
|
|
||||||
int x = gueltigeEingabe(in, "x");
|
String ergebnis = new Schachbrett().feldname(0,0);
|
||||||
int y = gueltigeEingabe(in, "y");
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
Schachbrett instanz = new Schachbrett();
|
|
||||||
String ergebnis = instanz.feldname(y-1,x-1);
|
|
||||||
System.out.println("Die Position auf dem Schachbrett ist: " + ergebnis);
|
System.out.println("Die Position auf dem Schachbrett ist: " + ergebnis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue