Pr_robot_factory/domain/Factory.java

40 lines
858 B
Java
Raw Normal View History

package domain;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
public class Factory implements Serializable {
private HashMap<Integer, Robot> robots = new HashMap<>();
private int c3poID = 0;
2023-01-06 22:55:33 +01:00
private int r2d2ID = 10000;
public Factory(){
}
//Has to return Collection<Robot>
public Collection<Robot> getRobotList(){
return robots.values();
}
public boolean buildNewRobot(String name, int type){
Robot r ;
if(type == 0){
r = new R2D2(r2d2ID++, name);
}else if(type == 1){
r = new C3PO(c3poID++, name);
}else{
return false;
}
robots.put(r.getId(), r);
return true;
}
2023-01-06 22:55:33 +01:00
public Robot getRobotOfList(int id){
return robots.get(id);
}
}