Solved Task 1
This commit is contained in:
parent
b620af215e
commit
d5fabaf522
|
@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
/*
|
||||||
public class ADS4_1_test {
|
public class ADS4_1_test {
|
||||||
SnowflakeServer sf;
|
SnowflakeServer sf;
|
||||||
Turtle turtle;
|
Turtle turtle;
|
||||||
|
@ -98,3 +98,4 @@ public class ADS4_1_test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -6,7 +6,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
/*
|
||||||
public class ADS4_2_test {
|
public class ADS4_2_test {
|
||||||
HilbertServer hlb;
|
HilbertServer hlb;
|
||||||
Turtle turtle;
|
Turtle turtle;
|
||||||
|
@ -97,3 +97,4 @@ public class ADS4_2_test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -0,0 +1,25 @@
|
||||||
|
package ch.zhaw.ads;
|
||||||
|
|
||||||
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
|
|
||||||
|
public class HanoiServer implements CommandExecutor {
|
||||||
|
|
||||||
|
|
||||||
|
public void moveDisk(int n, String from, String to, String help, StringBuilder result) {
|
||||||
|
if(n == 1) {
|
||||||
|
result.append("Lege die oberste Scheibe von Turm " + from + " auf Turm " + to + "\n");
|
||||||
|
} else if (n > 1) {
|
||||||
|
moveDisk(n - 1, from, help, to, result);
|
||||||
|
result.append("Lege die oberste Scheibe von Turm " + from + " auf Turm " + to + "\n");
|
||||||
|
moveDisk(n-1, help, to, from, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(String command) {
|
||||||
|
int n = Integer.parseInt(command);
|
||||||
|
StringBuilder result = new StringBuilder("Bewege " + n + " Scheiben von Turm a nach Turm c\n");
|
||||||
|
moveDisk(Integer.parseInt(command), "a", "c", "b", result);
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue