Tach zusammen,
haben so ein java übungsblatt erhalten wo wir eine art schiebepuzzle implementieren sollen! die bewegungen nach den 4 himmelsrichtungen habe ic hfolgendermassen kodiert:
(es fkt. habe weiter unten zum hauptprogramm ne frage)
jetzt noch das hauptprogramm zur steuerung:
wenn ich nun aber die hauptprog.java compilen will kommt folgende fehlermeldung:
hans@hans-desktop:~/Desktop/Aufgabe6_1$ javac hauptprog.java
----------
1. ERROR in hauptprog.java (at line 10)
operation xy;
^^^^^^^^^
operation cannot be resolved to a type
----------
2. ERROR in hauptprog.java (at line 11)
xy = operation();
^^^^^^^^^
The method operation() is undefined for the type hauptprog
----------
Da hat ja dann irgendetwas mit der Übergabe der Instanzen oder so nicht ganz fkt? finde den fehler grade nicht!
bin für tipps dankbar
mfg
hans
haben so ein java übungsblatt erhalten wo wir eine art schiebepuzzle implementieren sollen! die bewegungen nach den 4 himmelsrichtungen habe ic hfolgendermassen kodiert:
(es fkt. habe weiter unten zum hauptprogramm ne frage)
Code:
class operation {
public static void left(int[][] puzzle) {
int temp1 =0;
int temp2 =0;
for (int u = 0; u < puzzle.length; u++) {
if (puzzle[u][0] == 0) {
temp2 = 0;
temp1 = u;
break;
}
if (puzzle[u][1] == 0) {
temp2 = 1;
temp1 = u;
break;
}
if (puzzle[u][2] == 0) {
temp2 = 2;
temp1 = u;
break;
}
}
int hilfsvariable = temp2 - 1;
int zwischenspeicher = puzzle[temp1][hilfsvariable];
puzzle[temp1][temp2] = zwischenspeicher;
puzzle[temp1][hilfsvariable] = 0;
for(int i=0; i<3; i++) {
System.out.println("|"+ puzzle[i][0]+ "|" +puzzle[i][1]+ "|" + puzzle[i][2] + "|");
}
}
public static void right(int[][] puzzle) {
int temp1 =0;
int temp2 =0;
for (int u = 0; u < puzzle.length; u++) {
if (puzzle[u][0] == 0) {
temp2 = 0;
temp1 = u;
break;
}
if (puzzle[u][1] == 0) {
temp2 = 1;
temp1 = u;
break;
}
if (puzzle[u][2] == 0) {
temp2 = 2;
temp1 = u;
break;
}
}
int hilfsvariable = temp2 + 1;
int zwischenspeicher = puzzle[temp1][hilfsvariable];
puzzle[temp1][temp2] = zwischenspeicher;
puzzle[temp1][hilfsvariable] = 0;
for(int i=0; i<3; i++) {
System.out.println("|"+ puzzle[i][0]+ "|" +puzzle[i][1]+ "|" + puzzle[i][2] + "|");
}
}
public static void down(int[][] puzzle) {
int temp1 =0;
int temp2 =0;
for (int u = 0; u < puzzle.length; u++) {
if (puzzle[u][0] == 0) {
temp2 = 0;
temp1 = u;
break;
}
if (puzzle[u][1] == 0) {
temp2 = 1;
temp1 = u;
break;
}
if (puzzle[u][2] == 0) {
temp2 = 2;
temp1 = u;
break;
}
}
int hilfsvariable = temp1 + 1;
int zwischenspeicher = puzzle[hilfsvariable][temp2];
puzzle[temp1][temp2] = zwischenspeicher;
puzzle[hilfsvariable][temp2] = 0;
for(int i=0; i<3; i++) {
System.out.println("|"+ puzzle[i][0]+ "|" +puzzle[i][1]+ "|" + puzzle[i][2] + "|");
}
}
public static void up(int[][] puzzle) {
int temp1 =0;
int temp2 =0;
for (int u = 0; u < puzzle.length; u++) {
if (puzzle[u][0] == 0) {
temp2 = 0;
temp1 = u;
break;
}
if (puzzle[u][1] == 0) {
temp2 = 1;
temp1 = u;
break;
}
if (puzzle[u][2] == 0) {
temp2 = 2;
temp1 = u;
break;
}
}
int hilfsvariable = temp1 - 1;
int zwischenspeicher = puzzle[hilfsvariable][temp2];
puzzle[temp1][temp2] = zwischenspeicher;
puzzle[hilfsvariable][temp2] = 0;
for(int i=0; i<3; i++) {
System.out.println("|"+ puzzle[i][0]+ "|" +puzzle[i][1]+ "|" + puzzle[i][2] + "|");
}
}
int gibanzahlderschritteaus(int anzahlderschritte) {
return anzahlderschritte;
}
}
jetzt noch das hauptprogramm zur steuerung:
Code:
import java.io.*;
public class hauptprog {
public static void main (String[] args) throws IOException {
int puzzle[][] = {{0,8,3},{2,1,4},{7,6,5}};
int einlesen;
int anzahlderschritte = 0;
operation xy;
xy = operation();
for(int i=0; i<3; i++) {
System.out.println("|"+ puzzle[i][0]+ "|" +puzzle[i][1]+ "|" + puzzle[i][2] + "|");
}
do {
einlesen = System.in.read();
if (einlesen == 'l') {
if (puzzle[0][0] == 0 || puzzle[1][0] == 0 || puzzle[2][0] == 0) {
System.out.println("Nicht moeglich!");
}
else {
xy.left(puzzle);
anzahlderschritte++;
}
}
if (einlesen == 'r') {
if (puzzle[0][2] == 0 || puzzle[1][2] == 0 || puzzle[2][2] == 0) {
System.out.println("Nicht moeglich!");
}
else {
xy.right(puzzle);
anzahlderschritte++;
}
}
if (einlesen == 'd') {
if (puzzle[2][0] == 0 || puzzle[2][1] == 0 || puzzle[2][2] == 0) {
System.out.println("Nicht moeglich!");
}
else {
xy.down(puzzle);
anzahlderschritte++;
}
}
if (einlesen == 'u') {
if (puzzle[0][0] == 0 || puzzle[0][1] == 0 || puzzle[0][2] == 0) {
System.out.println("Nicht moeglich!");
}
else {
xy.up(puzzle);
anzahlderschritte++;
}
}
}while (einlesen != '#');
System.out.println("Anzahl der Schritte: " + xy.gibanzahlderschritteaus());
}
}
wenn ich nun aber die hauptprog.java compilen will kommt folgende fehlermeldung:
hans@hans-desktop:~/Desktop/Aufgabe6_1$ javac hauptprog.java
----------
1. ERROR in hauptprog.java (at line 10)
operation xy;
^^^^^^^^^
operation cannot be resolved to a type
----------
2. ERROR in hauptprog.java (at line 11)
xy = operation();
^^^^^^^^^
The method operation() is undefined for the type hauptprog
----------
Da hat ja dann irgendetwas mit der Übergabe der Instanzen oder so nicht ganz fkt? finde den fehler grade nicht!
bin für tipps dankbar
mfg
hans