Pr_robot_factory/domain/R2D2.java

73 lines
2.0 KiB
Java
Raw Normal View History

2022-12-08 14:58:44 +01:00
package domain;
2022-12-14 10:18:36 +01:00
import robot.exceptions.ExceptionStorage;
2022-12-14 09:54:18 +01:00
import robot.exceptions.RobotException;
import robot.exceptions.robotExceptions;
2022-12-14 09:54:18 +01:00
2022-12-09 00:30:35 +01:00
public class R2D2 extends RobotBasics {
/**
*
* @param id> int
* @param name> String
*/
public R2D2(int id, String name){
super(id, name);
}
public int[] think(int[] input) throws RobotException {
2022-12-14 10:18:36 +01:00
if(isPowerOn()){
return selectionSort(input);
2022-12-14 09:54:18 +01:00
}else{
this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName()));
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
2022-12-14 09:54:18 +01:00
}
}
/*
* this method sorts
* @param input
* @return integer array
* @throws RobotException
public int[] sorting(int[] input) throws RobotException {
if(checkArray(input)){
//Selectionsort
int small;
for (int i = 0; i <input.length - 1; i++) {
small = i;
for (int j = i + 1; j < input.length; j++) {
//if there is a smaller number on this position
if (input[j] < input[small]) {
small = j;
//swap values
int temp = input[i];
input[i] = input[small];
input[small] = temp;
}
2022-12-14 10:18:36 +01:00
}
}
return input;
}else{
throw new RobotException(robotExceptions.MAGICVALUE, getName());
2022-12-14 10:18:36 +01:00
}
}*/
2022-12-14 09:54:18 +01:00
2022-12-14 11:08:49 +01:00
/**
* Die Methode nimmt ein Array aus int entgegen und wandelt diese in einen String um.
* @param input Zahlen, die ausgegeben werden sollen.
* @return String oder null
* @throws RobotException
*/
@Override
public String speak(int[] input) throws RobotException {
if (isPowerOn()) {
return ausgabe(input, ";");
} else {
this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName()));
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
2022-12-14 11:08:49 +01:00
}
}
2022-12-14 10:18:36 +01:00
}