RobotFactoryImplemented
parent
6415b936c7
commit
bd3a5c4c2b
|
@ -7,9 +7,12 @@ import java.util.stream.Collectors;
|
|||
public class C3PO implements Robot {
|
||||
private int id;
|
||||
private String name;
|
||||
private boolean isPowerOn;
|
||||
|
||||
private boolean isPowerOn=false;
|
||||
|
||||
public C3PO(int id, String name){
|
||||
this.id=id;
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
|
|
|
@ -9,6 +9,11 @@ public class R2D2 implements Robot {
|
|||
private String name;
|
||||
private boolean isPowerOn;
|
||||
|
||||
public R2D2(int id, String name){
|
||||
this.id=id;
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import tpe.exceptions.roboter.Robot;
|
||||
|
||||
public class RobotFactory {
|
||||
private static int R2D2Id=0;
|
||||
private static int C2POId=10000;
|
||||
public static Robot getRobot(String typ){
|
||||
switch (typ){
|
||||
case "R2D2":
|
||||
return new R2D2(R2D2Id++,"blah");
|
||||
|
||||
case "C3PO":
|
||||
return new C3PO(C2POId++,"blah");
|
||||
|
||||
case "Nexus6":
|
||||
return Nexus6.getInstance();
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue