我被困在作业的一部分。我不知道如何将代理运送到另一个空间。如何将代理移动到空间
将方法usePortal
添加到没有参数和void返回类型的Agent类。 此方法获取代理的位置的门户,并检查它是否为空。
•如果门户网站不为空,请让门户网站使用门户网站的 传输方法传输代理程序。您将需要使用这个词来指代需要运输的代理商 。
•如果门户网站为空,则不要执行任何操作。
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;
}
}
'Portal'类是否有'transport()'方法? – 2014-09-29 00:53:03
public void transport(代理学生){ student.set_location(_destination);}我不知道如何在代理类中调用此方法 – 2014-09-29 00:53:30