RobotFactoryImplemented

master
azadehobenland 2023-01-05 19:03:42 +01:00
parent 6415b936c7
commit bd3a5c4c2b
3 changed files with 31 additions and 2 deletions

View File

@ -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() {

View File

@ -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

View File

@ -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;
}
}