Hallo, ich habe folgende 2 Klassen:
[CODE lang="java" title="Roboter"]public class Roboter {
public Decision reaktToRisk(String risk){
DangerousSituation[] situations = DangerousSituation.values();
for(int i = 0; i < situations.length; i++){
if(situations.toString().equals(risk)){
// Returns the value of Decision at the position of the situation -1 because we are in an array
return Decision.values()[situations.ordinal()];
}
}
// if there isn´t any situation with the given risk an error will be thrown
throw new RuntimeException("No decision found for this risk!");
}
}[/CODE]
[CODE lang="java" title="Person"]public class Person extends Roboter{
@Override
public Decision reaktToRisk(String risk) {
// returns
if (Math.random()<=0.25) {
return Decision.values()[3];
} else{
return super.reaktToRisk(risk);
}
}
}[/CODE]
Jetzt soll ich eine neue Klasse schreiben, welche sowohl ein Roboter, als auch eine Person ist. Die Klasse soll Cyborg heißen. Wenn ich "extends Person, Roboter" versuche, bekomme ich angezeigt, dass es ein Fehler ist, aber nicht warum. Ich verstehe auch nicht ganz, was da das Problem ist.
Vielen Dank für Eure Hilfe!
[CODE lang="java" title="Roboter"]public class Roboter {
public Decision reaktToRisk(String risk){
DangerousSituation[] situations = DangerousSituation.values();
for(int i = 0; i < situations.length; i++){
if(situations.toString().equals(risk)){
// Returns the value of Decision at the position of the situation -1 because we are in an array
return Decision.values()[situations.ordinal()];
}
}
// if there isn´t any situation with the given risk an error will be thrown
throw new RuntimeException("No decision found for this risk!");
}
}[/CODE]
[CODE lang="java" title="Person"]public class Person extends Roboter{
@Override
public Decision reaktToRisk(String risk) {
// returns
if (Math.random()<=0.25) {
return Decision.values()[3];
} else{
return super.reaktToRisk(risk);
}
}
}[/CODE]
Jetzt soll ich eine neue Klasse schreiben, welche sowohl ein Roboter, als auch eine Person ist. Die Klasse soll Cyborg heißen. Wenn ich "extends Person, Roboter" versuche, bekomme ich angezeigt, dass es ein Fehler ist, aber nicht warum. Ich verstehe auch nicht ganz, was da das Problem ist.
Vielen Dank für Eure Hilfe!