First Draft
parent
abb6258468
commit
09d7536d36
|
@ -0,0 +1,53 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class Schachbrett {
|
||||
//bauen eines schachbretts Feldname(0,0) -> "A1"
|
||||
private String[][] felder;
|
||||
|
||||
public Schachbrett() {
|
||||
felder = new String[][] {{"A","B","C","D","E","F","G","H"},{"1","2","3","4","5","6","7","8"}};
|
||||
|
||||
}
|
||||
|
||||
public static boolean istEingabeUngueltig(int Zahl) {
|
||||
if (Zahl < 1 || Zahl > 8) {
|
||||
System.out.println("Falsche Eingabe, bitte gebe eine Zahl zwischen 1 und 8 ein.");
|
||||
return true;
|
||||
|
||||
} else return false;
|
||||
|
||||
}
|
||||
|
||||
public String feldname(int row, int col) {
|
||||
String Ergebnis = felder[0][col] + felder[1][row];
|
||||
return Ergebnis;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
|
||||
in.close();
|
||||
|
||||
Schachbrett instanz = new Schachbrett();
|
||||
String ergebnis = instanz.feldname(y-1,x-1);
|
||||
System.out.println("Die Position auf dem Schachbrett ist: " + ergebnis);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue