私は宿題の一部で立ち往生しています。エージェントを別のスペースに移動する方法がわかりません。
usePortal
パラメーターがなく、戻り値の型が voidのメソッドを Agent クラスに追加します。このメソッドは、エージェントの場所のポータルを取得し、それが null かどうかを確認します。
• ポータルが null でない場合は、ポータルのトランスポート メソッドを使用してポータルにエージェントをトランスポートさせます。移送する必要のあるエージェントを指すには、this という単語を使用する必要があります。
• ポータルが null の場合は、何もしないでください。
public class Agent {
private Space _location;
private String _name;
public Space get_location() {
return _location;
}
public void set_location(Space _location) {
this._location = _location;
}
public String get_name() {
return _name;
}
public void set_name(String _name) {
this._name = _name;
}
public String toString(){
return _name;
}
public String toStringLong(){
return _name + " is in " + _location;
}
public void usePortal(){
if(Portal.get_destination() == null){
}else{
}
}
}
public class Portal {
private static String _name;
private static String _direction;
private static Space _destination;
public String get_name() {
return _name;
}
public void set_name(String _name) {
Portal._name = _name;
}
public String get_direction() {
return _direction;
}
public void set_direction(String _direction) {
Portal._direction = _direction;
}
public static Space get_destination() {
return _destination;
}
public void set_destination(Space _destination) {
Portal._destination = _destination;
}
public String toString(){
return _name + " that goes " + _direction;
}
public String toStringLong(){
return _name + " that goes " + _direction + " to " + _destination;
}
public void transport(Agent student){
student.set_location(_destination);
}
}
public class Space {
Portal p = new Portal();
private String _name;
private String _description;
private Portal _portal;
public String get_name() {
return _name;
}
public void set_name(String _name) {
this._name = _name;
}
public String get_description() {
return _description;
}
public void set_description(String _description) {
this._description = _description;
}
public Portal get_portal() {
return _portal;
}
public void set_portal(Portal _portal) {
this._portal = _portal;
}
public String toString() {
return _name;
}
public String toStringLong(){
if (_portal != null){
return _name + ": " + _description + " with a " + p.toStringLong();
}
return _name + ": " + _description;
}
}