From 6807b436c507fde60ebdee21c62f102e68c4165f Mon Sep 17 00:00:00 2001 From: 2120940 <2120940@stud.hs-mannheim.de> Date: Sat, 7 Jan 2023 11:19:18 +0100 Subject: [PATCH] weitere Implementierung Nexus6 und Random ID bei R2D2 (noch nicht final) --- Roboter/tpe/exceptions/roboter/Nexus6.java | 55 +++++++++++++++++++++- Roboter/tpe/exceptions/roboter/R2D2.java | 9 ++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/Roboter/tpe/exceptions/roboter/Nexus6.java b/Roboter/tpe/exceptions/roboter/Nexus6.java index 6bf4d7c..fb44f48 100644 --- a/Roboter/tpe/exceptions/roboter/Nexus6.java +++ b/Roboter/tpe/exceptions/roboter/Nexus6.java @@ -1,5 +1,58 @@ package tpe.exceptions.roboter; -public class Nexus6 { +import tpe.exceptions.roboter.exceptions.RobotException; + +public class Nexus6 implements RobotControl, RobotInstructions { + private static int id=19281982; + private static String name="Pris"; + private static boolean powerSwitch=false; + private static Nexus6 instance = new Nexus6(id, name, powerSwitch); + + private Nexus6(int id, String name, boolean powerSwitch) { + super(); + + } + + public static Nexus6 getInstance() { + return instance; + } + @Override + public String speak(int[] zahlen) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int[] think(int[] zahlen) { + // TODO Auto-generated method stub + return null; + } + + public int getId() { + + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void triggerPowerSwitch() { + powerSwitch=false; + } + + @Override + public boolean isPowerOn() { + return powerSwitch; + } + + + @Override + public RobotException getLastException() { + // TODO Auto-generated method stub + return null; + } } diff --git a/Roboter/tpe/exceptions/roboter/R2D2.java b/Roboter/tpe/exceptions/roboter/R2D2.java index b35e9c4..ed51fe1 100644 --- a/Roboter/tpe/exceptions/roboter/R2D2.java +++ b/Roboter/tpe/exceptions/roboter/R2D2.java @@ -1,10 +1,10 @@ package tpe.exceptions.roboter; +import java.util.*; import tpe.exceptions.roboter.exceptions.RobotException; import tpe.exceptions.roboter.exceptions.RobotMagicValueException; public class R2D2 implements RobotControl, RobotInstructions { - private static int counter = 0; private String name; private boolean powerSwitch; private int id; @@ -13,11 +13,14 @@ public class R2D2 implements RobotControl, RobotInstructions { public R2D2(String name, boolean powerSwitch) { super(); - id = 0+counter; + id = createId(); this.name = name; this.powerSwitch = powerSwitch; } - + private int createId() { + Random randomID = new Random(); + return randomID.nextInt(10000); + } @Override public int getId() {