updated R2D2
parent
c928bb028e
commit
2a68c15468
12
Main.java
12
Main.java
|
@ -1,5 +1,4 @@
|
|||
import domain.C3PO;
|
||||
import domain.R2D2;
|
||||
import robot.exceptions.RobotException;
|
||||
|
||||
public class Main {
|
||||
|
@ -12,17 +11,8 @@ public class Main {
|
|||
//Herbert.triggerPowerSwitch();
|
||||
//Gudrun.triggerPowerSwitch();
|
||||
|
||||
try{
|
||||
Herbert.speak(input);
|
||||
}catch(RobotException re){
|
||||
System.out.println(re);
|
||||
}
|
||||
|
||||
try{
|
||||
Gudrun.think(input2);
|
||||
}catch(RobotException re){
|
||||
System.out.println(re);
|
||||
}
|
||||
|
||||
//System.out.println("Was neues ausgeben");
|
||||
|
||||
//just some testing
|
||||
|
|
|
@ -1,36 +1,57 @@
|
|||
package domain;
|
||||
|
||||
|
||||
import robot.exceptions.RobotException;
|
||||
import robot.exceptions.RobotIllegalStateException;
|
||||
import robot.interfaces.Sorting;
|
||||
|
||||
public class R2D2 extends RobotBasics {
|
||||
/**
|
||||
* Constructor
|
||||
* @param id> int
|
||||
* @param name> String
|
||||
@@ -8,7 +12,35 @@ public class R2D2 extends RobotBasics {
|
||||
*/
|
||||
public R2D2(int id, String name){
|
||||
super(id, name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
if(isPowerOn() == true){
|
||||
return selectionsSort.sorting(zahlen);
|
||||
|
||||
if(isPowerOn()){
|
||||
return sorting(zahlen);
|
||||
}else{
|
||||
throw new RobotIllegalStateException(getName() + " is turned off.");
|
||||
throw new RobotIllegalStateException(getName() + " is turned off!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Selectionsort...
|
||||
Sorting selectionsSort = (int[] input) -> {
|
||||
System.out.println("ich sortiere mit selection-Sort");
|
||||
|
||||
return input;
|
||||
};
|
||||
public int[] sorting(int[] arr) {
|
||||
//Selectionsort
|
||||
int small;
|
||||
for (int i = 0; i <arr.length - 1; i++) {
|
||||
small = i;
|
||||
for (int j = i + 1; j < arr.length; j++) {
|
||||
//if there is a smaller number on this position
|
||||
if (arr[j] < arr[small]) {
|
||||
small = j;
|
||||
//swap values
|
||||
int temp = arr[i];
|
||||
arr[i] = arr[small];
|
||||
arr[small] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
/*
|
||||
//Writing all values of the array into a String
|
||||
String result = "";
|
||||
if(arr.length != 0) {
|
||||
result = "" + arr[0];
|
||||
if (arr.length > 1) {
|
||||
for (int i = 1; i < arr.length; i++) {
|
||||
result += "," + arr[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
*/
|
||||
|
||||
}
|
Loading…
Reference in New Issue