updated Exceptions with Enum of errormessages and Exception Storage. Also added a new Exception *ArrayEmptyException* and an Exception Storage to get the last Exception that occured.
parent
de13ede97d
commit
d7a505607d
36
Main.java
36
Main.java
|
@ -5,21 +5,49 @@ public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
int[] input = {42,6,5,4,3,2,1};
|
int[] input = {42,6,5,4,3,43,1};
|
||||||
int[] input2 = input;
|
int[] input2 = input;
|
||||||
C3PO Herbert = new C3PO(1, "Herbert");
|
C3PO Herbert = new C3PO(1, "Herbert");
|
||||||
R2D2 Herb = new R2D2(0, "Herb");
|
R2D2 Herb = new R2D2(0, "Herb");
|
||||||
|
int[] input3 = {};
|
||||||
|
|
||||||
//Herbert.triggerPowerSwitch();
|
//Herbert.triggerPowerSwitch();
|
||||||
Herb.triggerPowerSwitch();
|
// Herb.triggerPowerSwitch();
|
||||||
|
|
||||||
|
|
||||||
|
// try{
|
||||||
|
// String sorted = Herb.speak(input);
|
||||||
|
// System.out.println(sorted);
|
||||||
|
// } catch (RobotException re) {
|
||||||
|
// System.out.println(re);
|
||||||
|
// }
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String array = Herb.speak(input);
|
int[] sorted = Herb.think(input);
|
||||||
System.out.println(array);
|
for(int i = 0; i < sorted.length; i++){
|
||||||
|
System.out.print(" " + sorted[i]);
|
||||||
|
}
|
||||||
|
}catch(RobotException re){
|
||||||
|
System.out.println(re);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String re = Herb.getLastException().toString();
|
||||||
|
System.out.println(re);
|
||||||
|
|
||||||
|
Herb.triggerPowerSwitch();
|
||||||
|
|
||||||
|
try{
|
||||||
|
int[] sorted = Herb.think(input);
|
||||||
|
for(int i = 0; i < sorted.length; i++){
|
||||||
|
System.out.print(" " + sorted[i]);
|
||||||
|
}
|
||||||
}catch(RobotException e){
|
}catch(RobotException e){
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
|
re = Herb.getLastException().toString();
|
||||||
|
System.out.println(re);
|
||||||
|
|
||||||
//System.out.println("Was neues ausgeben");
|
//System.out.println("Was neues ausgeben");
|
||||||
|
|
||||||
//just some testing
|
//just some testing
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package domain;
|
package domain;
|
||||||
|
|
||||||
import robot.exceptions.RobotException;
|
import robot.exceptions.RobotException;
|
||||||
import robot.exceptions.RobotIllegalStateException;
|
import robot.exceptions.robotExceptions;
|
||||||
import robot.exceptions.RobotMagicValueException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -18,27 +17,47 @@ public class C3PO extends RobotBasics {
|
||||||
.mapToObj(Integer::toString)
|
.mapToObj(Integer::toString)
|
||||||
.collect(Collectors.joining("; "));
|
.collect(Collectors.joining("; "));
|
||||||
}else{
|
}else{
|
||||||
throw new RobotMagicValueException(getName() + " has an unknown Error. Code 42.");
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
||||||
|
// throw new RobotMagicValueException(getName() + " has an unknown Error. Code 42.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String speak(int[] zahlen) throws RobotException {
|
public String speak(int[] input) throws RobotException {
|
||||||
//Insertionsort
|
|
||||||
if(isPowerOn()){
|
if(isPowerOn()){
|
||||||
try{
|
try{
|
||||||
return ausgabe(zahlen);
|
return ausgabe(input);
|
||||||
}catch(RobotException re){
|
}catch(RobotException re){
|
||||||
return re.toString();
|
return re.toString();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
throw new RobotIllegalStateException(getName() + " is turned off.");
|
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
|
||||||
|
//throw new RobotIllegalStateException(getName() + " is turned off.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] sorting(int[] input) throws RobotException{
|
||||||
|
if(input.length != 0 ){
|
||||||
|
if(checkArray(input)){
|
||||||
|
//sort
|
||||||
|
}else{
|
||||||
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
||||||
|
//throw new RobotMagicValueException(getName() + " has an unknown error. Code 42");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
|
||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public int[] think(int[] input) throws RobotException {
|
||||||
|
//Insertionsort
|
||||||
|
if(isPowerOn()){
|
||||||
|
return sorting(input);
|
||||||
|
}else{
|
||||||
|
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
|
||||||
|
// throw new RobotIllegalStateException(getName() + " is turned off.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
package domain;
|
package domain;
|
||||||
|
|
||||||
|
|
||||||
|
import robot.exceptions.ExceptionStorage;
|
||||||
import robot.exceptions.RobotException;
|
import robot.exceptions.RobotException;
|
||||||
import robot.exceptions.RobotIllegalStateException;
|
import robot.exceptions.robotExceptions;
|
||||||
import robot.exceptions.RobotMagicValueException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
import java.util.function.IntPredicate;
|
|
||||||
import java.util.stream.Collector;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class R2D2 extends RobotBasics {
|
public class R2D2 extends RobotBasics {
|
||||||
/**
|
/**
|
||||||
|
@ -22,53 +15,45 @@ public class R2D2 extends RobotBasics {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Sorting sort = (int[] input) -> {
|
|
||||||
|
public int[] think(int[] input) throws RobotException {
|
||||||
|
if(isPowerOn()){
|
||||||
|
return selectionSort(input);
|
||||||
|
}else{
|
||||||
|
this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName()));
|
||||||
|
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this method sorts
|
||||||
|
* @param input
|
||||||
|
* @return integer array
|
||||||
|
* @throws RobotException
|
||||||
|
|
||||||
|
public int[] sorting(int[] input) throws RobotException {
|
||||||
|
if(checkArray(input)){
|
||||||
|
//Selectionsort
|
||||||
int small;
|
int small;
|
||||||
for (int i = 0; i <input.length - 1; i++) {
|
for (int i = 0; i <input.length - 1; i++) {
|
||||||
small = i;
|
small = i;
|
||||||
for (int j = i + 1; j < input.length; j++) {
|
for (int j = i + 1; j < input.length; j++) {
|
||||||
if(input[j] < )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
|
||||||
if(isPowerOn()){
|
|
||||||
return sorting(zahlen);
|
|
||||||
}else{
|
|
||||||
throw new RobotIllegalStateException(getName() + " is turned off!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 there is a smaller number on this position
|
||||||
if (arr[j] < arr[small]) {
|
if (input[j] < input[small]) {
|
||||||
small = j;
|
small = j;
|
||||||
//swap values
|
//swap values
|
||||||
int temp = arr[i];
|
int temp = input[i];
|
||||||
arr[i] = arr[small];
|
input[i] = input[small];
|
||||||
arr[small] = temp;
|
input[small] = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arr;
|
return input;
|
||||||
|
}else{
|
||||||
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diese ganze Methode muss zu C3P0 und ist hier falsch.
|
}*/
|
||||||
public String ausgabe(int[] input)throws RobotException{
|
|
||||||
if(input.length != 0 && !checkArray(input)) {
|
|
||||||
return Arrays.stream(input)
|
|
||||||
.mapToObj(Integer::toString)
|
|
||||||
.collect(Collectors.joining("; "));
|
|
||||||
}else{
|
|
||||||
throw new RobotMagicValueException(getName() +" has an unknown Error. Code 42.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die Methode nimmt ein Array aus int entgegen und wandelt diese in einen String um.
|
* Die Methode nimmt ein Array aus int entgegen und wandelt diese in einen String um.
|
||||||
|
@ -78,21 +63,11 @@ public class R2D2 extends RobotBasics {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String speak(int[] input) throws RobotException {
|
public String speak(int[] input) throws RobotException {
|
||||||
final boolean[] found_42 = {false};
|
|
||||||
if (isPowerOn()) {
|
if (isPowerOn()) {
|
||||||
try{
|
return ausgabe(input, ";");
|
||||||
return ausgabe(input);
|
|
||||||
}catch(RobotException re){
|
|
||||||
return re.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new RobotIllegalStateException(getName() + " is turned off!");
|
this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName()));
|
||||||
|
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void something() {
|
|
||||||
System.out.println("Hello");
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +1,16 @@
|
||||||
package domain;
|
package domain;
|
||||||
|
|
||||||
|
import robot.exceptions.ExceptionStorage;
|
||||||
import robot.exceptions.RobotException;
|
import robot.exceptions.RobotException;
|
||||||
import robot.exceptions.RobotIllegalStateException;
|
import robot.exceptions.robotExceptions;
|
||||||
import robot.interfaces.Robot;
|
import robot.interfaces.Robot;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
public abstract class RobotBasics implements Robot {
|
public abstract class RobotBasics implements Robot {
|
||||||
|
protected ExceptionStorage exceptions;
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
private boolean power;
|
private boolean power;
|
||||||
|
@ -16,7 +19,9 @@ public abstract class RobotBasics implements Robot {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.power = false;
|
this.power = false;
|
||||||
|
this.exceptions = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see robot.interfaces.RobotControl;
|
* @see robot.interfaces.RobotControl;
|
||||||
*/
|
*/
|
||||||
|
@ -58,16 +63,98 @@ public abstract class RobotBasics implements Robot {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public RobotException getLastException() {
|
public RobotException getLastException() {
|
||||||
return null;
|
return exceptions.getLastErrorMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkArray(int[] input){
|
/**
|
||||||
|
* This method checks an array of integers and gives back a boolean value.
|
||||||
|
* If the array contains the number 42 the method returns false.
|
||||||
|
* Otherwise, always true.
|
||||||
|
*
|
||||||
|
* If the length of the Array = 0 it throws an EMPTYARRAY-Exception
|
||||||
|
* @param input
|
||||||
|
* @return boolean
|
||||||
|
* @throws RobotException EMPTYARRAY Exception
|
||||||
|
*/
|
||||||
|
public boolean checkArray(int[] input) throws RobotException{
|
||||||
|
if(input.length != 0){
|
||||||
for(int x: input){
|
for(int x: input){
|
||||||
if(x == 42){
|
if(x == 42){ return false; }
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}else{
|
||||||
}
|
this.exceptions = new ExceptionStorage(new RobotException(robotExceptions.EMPTYARRAY, getName()));
|
||||||
return false;
|
throw new RobotException(robotExceptions.EMPTYARRAY, getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method uses Streams to join any given array to a String.
|
||||||
|
*
|
||||||
|
* @param input int [ ]
|
||||||
|
* @param delemiter String
|
||||||
|
* @return String (array as String)
|
||||||
|
* @throws RobotException
|
||||||
|
*/
|
||||||
|
public String ausgabe(int[] input, String delemiter)throws RobotException{
|
||||||
|
if(checkArray(input)) {
|
||||||
|
return Arrays.stream(input)
|
||||||
|
.mapToObj(Integer::toString)
|
||||||
|
.collect(Collectors.joining(delemiter + " "));
|
||||||
|
}else{
|
||||||
|
this.exceptions = new ExceptionStorage(new RobotException(robotExceptions.MAGICVALUE, getName()));
|
||||||
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts any given array of integers with the insertion Sort algorithm.
|
||||||
|
* @param input int [ ]
|
||||||
|
* @return input int [ ] (sorted)
|
||||||
|
* @throws RobotException
|
||||||
|
*/
|
||||||
|
public int[] insertionSort(int[] input) throws RobotException{
|
||||||
|
if(checkArray(input)){
|
||||||
|
return new int[0];
|
||||||
|
}else{
|
||||||
|
this.exceptions = new ExceptionStorage(new RobotException(robotExceptions.MAGICVALUE, getName()));
|
||||||
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts any given array of integers with the selection Sort algorithm.
|
||||||
|
* @param input
|
||||||
|
* @return
|
||||||
|
* @throws RobotException
|
||||||
|
*/
|
||||||
|
public int[] selectionSort(int[] input) throws RobotException{
|
||||||
|
if(checkArray(input)){
|
||||||
|
int small;
|
||||||
|
for(int i = 0; i < input.length; i++){
|
||||||
|
small = i;
|
||||||
|
for(int j = i + 1; j < input.length; j++){
|
||||||
|
if(input[j] < input[small]){
|
||||||
|
small = j;
|
||||||
|
// System.out.println(small);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int temp = input[i];
|
||||||
|
input[i] = input[small];
|
||||||
|
input[small] = temp;
|
||||||
|
/*for(int n = 0; n < input.length; n++){
|
||||||
|
System.out.print( " " + input[n]);
|
||||||
|
}
|
||||||
|
System.out.println();*/
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}else{
|
||||||
|
this.exceptions = new ExceptionStorage(new RobotException(robotExceptions.MAGICVALUE, getName()));
|
||||||
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
- Philipp Kotte Matr. : 2211945;
|
- Philipp Kotte Matr. : 2211945;
|
||||||
- Cedric Hermann Matr. : 2210943;
|
- Cedric Hermann Matr. : 2210943;
|
||||||
- XXXXXXX XXXXX Matr. : XXXXXXX;
|
|
||||||
|
|
||||||
# Overview
|
# Overview
|
||||||
|
|
||||||
|
@ -44,6 +43,25 @@
|
||||||
* [Main](#-classe-main-)
|
* [Main](#-classe-main-)
|
||||||
* [makefile](#-makefile-for-Git-updates-)
|
* [makefile](#-makefile-for-Git-updates-)
|
||||||
|
|
||||||
|
# TO-Dos:
|
||||||
|
|
||||||
|
* Sortier Algorythem C3PO, R2D2 (mit Ausgabe)
|
||||||
|
|
||||||
|
* Bei Erstellung eines Roboters wird einne SerienNr erstellt
|
||||||
|
|
||||||
|
* Wichtige getter for Robots (getName)
|
||||||
|
|
||||||
|
* Exception Classes (Throwable einfügen)
|
||||||
|
|
||||||
|
* RobotFactory, die mit enum(RobotType) Objekt von R2 und C3PO erstellen kann
|
||||||
|
|
||||||
|
* Nexus6(Singleton) implementieren, kann nichts (Illegal-State)
|
||||||
|
|
||||||
|
* JUnit5 Tests
|
||||||
|
|
||||||
|
* Wie fügt man weitere Roboter hinzu erklärung in einer Text Datei
|
||||||
|
|
||||||
|
|
||||||
## Domain
|
## Domain
|
||||||
<h2 align="center"> Class R2D2 </h2>
|
<h2 align="center"> Class R2D2 </h2>
|
||||||
|
|
||||||
|
@ -350,3 +368,9 @@ Textdatei in Ihr Projekt, in der Sie die notwendigen Erweiterungen und evtl. Än
|
||||||
* Testen Sie Ihre Implementierung möglichst umfangreich. Wir werden es auf jeden Fall tun. !
|
* Testen Sie Ihre Implementierung möglichst umfangreich. Wir werden es auf jeden Fall tun. !
|
||||||
* Nutzen Sie für die gemeinsame Arbeit an der Implementierung ein Git-Repository und nutzen Sie regelmäßig.
|
* Nutzen Sie für die gemeinsame Arbeit an der Implementierung ein Git-Repository und nutzen Sie regelmäßig.
|
||||||
* Es müssen von allen Team-Mitgliedern jeweils mindestens fünf Commits mit substanziellem Inhalt auf den main-Branch gepusht werden.
|
* Es müssen von allen Team-Mitgliedern jeweils mindestens fünf Commits mit substanziellem Inhalt auf den main-Branch gepusht werden.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Fragen an Hummel
|
||||||
|
|
||||||
|
Was ist mit der Umwandlung von zahlen in arrays den inhalt mit Kommas getrennt gemeint?
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -15,6 +15,13 @@ update_domain:
|
||||||
git add domain/
|
git add domain/
|
||||||
git commit -m "Updated domain. Further explanation in README"
|
git commit -m "Updated domain. Further explanation in README"
|
||||||
git push -u origin main
|
git push -u origin main
|
||||||
|
update_exceptions:
|
||||||
|
git add robot/exceptions
|
||||||
|
git commit -m "Updated Exceptions"
|
||||||
|
git push -u origin main
|
||||||
|
update_interfaces:
|
||||||
|
git add robot/interfaces
|
||||||
|
git commit -m "updated interfaces"
|
||||||
|
git push -u origin main
|
||||||
fetch_git:
|
fetch_git:
|
||||||
git pull origin main
|
git pull origin main
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,7 @@
|
||||||
|
package robot.exceptions;
|
||||||
|
|
||||||
|
public class ArrayEmptyException extends RobotException{
|
||||||
|
public ArrayEmptyException(robotExceptions type,String errorMessage){
|
||||||
|
super(type, errorMessage);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package robot.exceptions;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
public class ExceptionStorage {
|
||||||
|
private RobotException message;
|
||||||
|
private LocalDateTime date;
|
||||||
|
|
||||||
|
public ExceptionStorage(RobotException message){
|
||||||
|
this.message = message;
|
||||||
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
this.date = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveLatestErrorMessage(RobotException message){
|
||||||
|
this.message = message;
|
||||||
|
this.date = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RobotException getLastErrorMessage(){
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public boolean emptyErrorStorage(){
|
||||||
|
if(this.message != ""){
|
||||||
|
this.message = "";
|
||||||
|
this.date = LocalDateTime.now();
|
||||||
|
return true;
|
||||||
|
}else{return false;}
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,22 @@
|
||||||
package robot.exceptions;
|
package robot.exceptions;
|
||||||
|
|
||||||
public class RobotException extends Exception{
|
public class RobotException extends Exception{
|
||||||
public RobotException(String errorMessage){
|
robotExceptions currentType;
|
||||||
super(errorMessage);
|
public RobotException(robotExceptions type, String name){
|
||||||
|
super(getMessage(type, name));
|
||||||
|
this.currentType = type;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getMessage(robotExceptions types, String name){
|
||||||
|
String message = "";
|
||||||
|
switch (types){
|
||||||
|
case ILLEGALSTATE: message = name + " is turned off."; break;
|
||||||
|
case MAGICVALUE: message = name + " has an unknown error. Code 42."; break;
|
||||||
|
case EMPTYARRAY: message = name + " got an empty array."; break;
|
||||||
|
}
|
||||||
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package robot.exceptions;
|
package robot.exceptions;
|
||||||
|
|
||||||
public class RobotIllegalStateException extends RobotException{
|
public class RobotIllegalStateException extends RobotException{
|
||||||
public RobotIllegalStateException(String errormessage){
|
|
||||||
super(errormessage);
|
public RobotIllegalStateException(robotExceptions type, String errormessage){
|
||||||
|
super(type, errormessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package robot.exceptions;
|
package robot.exceptions;
|
||||||
|
|
||||||
public class RobotMagicValueException extends RobotException {
|
public class RobotMagicValueException extends RobotException {
|
||||||
public RobotMagicValueException(String errormessage){
|
public RobotMagicValueException(robotExceptions type, String errormessage) {
|
||||||
super(errormessage);
|
super(type, errormessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package robot.exceptions;
|
||||||
|
|
||||||
|
public enum robotExceptions {
|
||||||
|
ILLEGALSTATE, MAGICVALUE, EMPTYARRAY
|
||||||
|
}
|
|
@ -30,23 +30,23 @@ public interface RobotInstructions {
|
||||||
* Gibt ein Array von Zahlen als String zurück. Die Zahlen werden
|
* Gibt ein Array von Zahlen als String zurück. Die Zahlen werden
|
||||||
* <b>nicht</b> sortiert.
|
* <b>nicht</b> sortiert.
|
||||||
*
|
*
|
||||||
* @param zahlen Zahlen, die ausgegeben werden sollen.
|
* @param numbers Zahlen, die ausgegeben werden sollen.
|
||||||
* @return Zahlen als String
|
* @return Zahlen als String
|
||||||
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
|
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
|
||||||
* oder das Array nicht seinen Vorstellungen entspricht.
|
* oder das Array nicht seinen Vorstellungen entspricht.
|
||||||
*/
|
*/
|
||||||
String speak(int[] zahlen) throws RobotException;
|
String speak(int[] numbers) throws RobotException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sortiert ein Array von Zahlen. Die Reihenfolge hängt von dem Typ des
|
* Sortiert ein Array von Zahlen. Die Reihenfolge hängt von dem Typ des
|
||||||
* Roboters ab.
|
* Roboters ab.
|
||||||
*
|
*
|
||||||
* @param zahlen Zahlen, die sortiert werden sollen.
|
* @param numbers Zahlen, die sortiert werden sollen.
|
||||||
* @return Sortierte Zahlen
|
* @return Sortierte Zahlen
|
||||||
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
|
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
|
||||||
* oder das Array nicht seinen Vorstellungen entspricht.
|
* oder das Array nicht seinen Vorstellungen entspricht.
|
||||||
*/
|
*/
|
||||||
int[] think(int[] zahlen) throws RobotException;
|
int[] think(int[] numbers) throws RobotException;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue