나는 숙제의 일부를 고수하고있다. 에이전트가 다른 공간으로 어떻게 옮겨 졌는지 확실하지 않습니다.공간으로 에이전트를 이동하는 방법
매개 변수 및 void 반환 유형이없는 에이전트 클래스에 usePortal
메서드를 추가합니다. 이 메소드는 에이전트의 위치 포털을 가져 와서 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;
}
}
'Portal' 클래스에'transport()'메소드가 있습니까? –
public void transport (에이전트 학생) { student.set_location (_destination);} 에이전트 클래스에서이 메서드를 호출하는 방법을 모르겠 음 –