1
Ich muss ein Objekt auf einer X- und Y-Achse Koordinaten rekursiv finden. In diesem speziellen Code muss ich „Remy“ finden, die immer wieder durch den Aufruf der SuchmethodeWie schreibe ich einen rekursiven Algorithmus mit Achse?
import java.awt.Point;
public class Sensor {
private Point target;
private Point[] points = {new Point(378, 349), new Point(147, 315), new Point(95, 375), new Point(242, 493), new Point(379, 389), new Point(168, 250), new Point(130, 220), new Point(160, 200), new Point(0, 0), new Point(0, 511), new Point(511, 0), new Point(511, 511)};
private String[] names = {"Bernstein", "DukeDog", "Huey", "Hedwig", "Flipper", "Remy", "QuadCat", "Nemo", "UL", "LL", "UR", "LR"};
public Sensor(String paramString) {
this.target = new Point(512, 512);
for (int i = 0; i < this.names.length; i++) {
if (paramString.equalsIgnoreCase(this.names[i])) {
this.target = this.points[i];
break;
}
}
}
public static void main(String[] args) {
Sensor sensor = new Sensor("Remy");
Point result = sensor.search(0, 0, 512);
if (result != null) {
System.out.println("location: " + result.x + "," + result.y);
} else {
System.out.println("unable to find");
}
}
public Point search(int x, int y, int width) {
//Write a recursive algorithm to find Remy calling the scan method repeatedly such as: scan(x,y,width);
//todo
return null;
}
public int scan(int paramInt1, int paramInt2, int paramInt3) {
if ((this.target.x >= paramInt1) && (this.target.x < paramInt1 + paramInt3) && (this.target.y >= paramInt2) && (this.target.y < paramInt2 + paramInt3)) {
return paramInt3;
} else {
return -paramInt3;
}
}
im Koordinaten 168.250 ist}
Beantwortet es Ihre Frage? – joel314