From 5679d63e717d498421a8dd6852690c50f821e463 Mon Sep 17 00:00:00 2001 From: 2120940 <2120940@stud.hs-mannheim.de> Date: Wed, 28 Dec 2022 12:22:05 +0100 Subject: [PATCH] =?UTF-8?q?Erste=20Funktionalit=C3=A4t=20bei=20R2D2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Roboter/tpe/exceptions/roboter/R2D2.java | 44 ++++++++++++++++++------ 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Roboter/tpe/exceptions/roboter/R2D2.java b/Roboter/tpe/exceptions/roboter/R2D2.java index cb44df9..cb57b29 100644 --- a/Roboter/tpe/exceptions/roboter/R2D2.java +++ b/Roboter/tpe/exceptions/roboter/R2D2.java @@ -3,29 +3,39 @@ package tpe.exceptions.roboter; import tpe.exceptions.roboter.exceptions.RobotException; public class R2D2 implements RobotControl, RobotInstructions { + private static int counter = 0; + private String name; + private boolean powerSwitch; + private int id; + + public R2D2(String name, boolean powerSwitch) { + super(); + id = 0+counter; + this.name = name; + this.powerSwitch = powerSwitch; + } @Override public int getId() { - // TODO Auto-generated method stub - return 0; + return id; } @Override public String getName() { - // TODO Auto-generated method stub - return null; + return name; } @Override public void triggerPowerSwitch() { - // TODO Auto-generated method stub - + if(powerSwitch=false) + powerSwitch=true; + else + powerSwitch=false; } @Override public boolean isPowerOn() { - // TODO Auto-generated method stub - return false; + return powerSwitch; } @Override @@ -42,8 +52,22 @@ public class R2D2 implements RobotControl, RobotInstructions { @Override public int[] think(int[] zahlen) { - // TODO Auto-generated method stub - return null; + // Iterate through zahlen from left to right + for (int i = 0; i < zahlen.length - 1; i++) { + // Set the index of the current smallest element to i + int minIndex = i; + // Search the smallest element in zahlen + for (int j = i + 1; j < zahlen.length; j++) { + if (zahlen[j] < zahlen[minIndex]) { + minIndex = j; + } + } + // Switch the smallest with the current element + int temp = zahlen[i]; + zahlen[i] = zahlen[minIndex]; + zahlen[minIndex] = temp; + } + return zahlen; } }