Updated everything. Further explanation in README
parent
542ac31f89
commit
b691e40c56
19
Main.java
19
Main.java
|
@ -1,18 +1,25 @@
|
|||
import domain.C3PO;
|
||||
import domain.*;
|
||||
import robot.exceptions.RobotException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
C3PO Herbert = new C3PO(0, "Herbert");
|
||||
R2D2 Gudrun = new R2D2(0, "Gdurun");
|
||||
int[] input = {6,5,4,3,2,1};
|
||||
|
||||
int[] input = {42,6,5,4,3,2,1};
|
||||
int[] input2 = input;
|
||||
C3PO Herbert = new C3PO(1, "Herbert");
|
||||
R2D2 Herb = new R2D2(0, "Herb");
|
||||
|
||||
//Herbert.triggerPowerSwitch();
|
||||
//Gudrun.triggerPowerSwitch();
|
||||
|
||||
Herb.triggerPowerSwitch();
|
||||
|
||||
|
||||
try{
|
||||
String array = Herb.speak(input);
|
||||
System.out.println(array);
|
||||
} catch (RobotException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
//System.out.println("Was neues ausgeben");
|
||||
|
||||
//just some testing
|
||||
|
|
|
@ -1,20 +1,45 @@
|
|||
package domain;
|
||||
|
||||
import robot.exceptions.RobotException;
|
||||
import robot.interfaces.Sorting;
|
||||
import robot.exceptions.RobotIllegalStateException;
|
||||
import robot.exceptions.RobotMagicValueException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class C3PO extends RobotBasics {
|
||||
public C3PO(int id, String name){
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String speak(int[] zahlen) throws RobotException {
|
||||
//Insertionsort
|
||||
if(isPowerOn()){
|
||||
try{
|
||||
return ausgabe(zahlen);
|
||||
}catch(RobotException re){
|
||||
return re.toString();
|
||||
}
|
||||
}else{
|
||||
throw new RobotIllegalStateException(getName() + " is turned off.");
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
return insertionSort.sorting(zahlen);
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
Sorting insertionSort = (int[] input) ->{
|
||||
System.out.println("ich sortiere mit insertion-Sort");
|
||||
return input;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,17 +3,35 @@ package domain;
|
|||
|
||||
import robot.exceptions.RobotException;
|
||||
import robot.exceptions.RobotIllegalStateException;
|
||||
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 {
|
||||
/**
|
||||
* Constructor
|
||||
@@ -8,7 +12,35 @@ public class R2D2 extends RobotBasics {
|
||||
*
|
||||
* @param id> int
|
||||
* @param name> String
|
||||
*/
|
||||
public R2D2(int id, String name){
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
/*Sorting sort = (int[] input) -> {
|
||||
int small;
|
||||
for(int i = 0; i < input.length -1; i++){
|
||||
small = i;
|
||||
for(int j = i + 1; j < input.length; j++){
|
||||
if(input[j] < )
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
if(isPowerOn()){
|
||||
return sorting(zahlen);
|
||||
|
@ -41,16 +59,15 @@ public class R2D2 extends RobotBasics {
|
|||
return arr;
|
||||
}
|
||||
|
||||
public String ausgabe(int[] input){
|
||||
String result = " ";
|
||||
if(input.length != 0) {
|
||||
result = " " + input[0];
|
||||
for(int i = 1; i < input.length; i++){
|
||||
result += "; " + input[i];
|
||||
// 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.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,10 +78,21 @@ public class R2D2 extends RobotBasics {
|
|||
*/
|
||||
@Override
|
||||
public String speak(int[] input) throws RobotException {
|
||||
final boolean[] found_42 = {false};
|
||||
if (isPowerOn()) {
|
||||
try{
|
||||
return ausgabe(input);
|
||||
}catch(RobotException re){
|
||||
return re.toString();
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new RobotIllegalStateException(getName() + " is turned off!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*public void something() {
|
||||
System.out.println("Hello");
|
||||
}*/
|
||||
}
|
||||
}
|
|
@ -2,10 +2,7 @@ package domain;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class R2D2Test {
|
||||
|
||||
|
@ -21,6 +18,7 @@ class R2D2Test {
|
|||
//Tests for basic functions
|
||||
@Test
|
||||
void getId() {
|
||||
|
||||
assertEquals(id, Herbert.getId());
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import robot.interfaces.Robot;
|
|||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class RobotBasics implements Robot {
|
||||
public abstract class RobotBasics implements Robot {
|
||||
private int id;
|
||||
private String name;
|
||||
private boolean power;
|
||||
|
@ -38,10 +38,10 @@ public class RobotBasics implements Robot {
|
|||
*/
|
||||
@Override
|
||||
public void triggerPowerSwitch() {
|
||||
if(power == false){
|
||||
power = true;
|
||||
}else{
|
||||
if(power){
|
||||
power = false;
|
||||
}else{
|
||||
power = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,32 +61,13 @@ public class RobotBasics implements Robot {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see robot.interfaces.RobotInstructions;
|
||||
* Maybe method is depractable
|
||||
*/
|
||||
@Override
|
||||
public String speak(int[] zahlen) throws RobotException {
|
||||
if(isPowerOn() == true){
|
||||
final String[] array = {""};
|
||||
Arrays.stream(zahlen).forEach(i -> array[0] += i + ", ");
|
||||
return array[0];
|
||||
}else{
|
||||
throw new RobotIllegalStateException( name + " is turned off.");
|
||||
public boolean checkArray(int[] input){
|
||||
for(int x: input){
|
||||
if(x == 42){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see robot.interfaces.RobotInstructions
|
||||
* Maybe method is depractable
|
||||
*/
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
if(isPowerOn() == true){
|
||||
return zahlen;
|
||||
}else{
|
||||
throw new RobotIllegalStateException(name + " is turned off");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package facade;
|
||||
|
||||
public class Factory {
|
||||
|
||||
}
|
||||
|
|
4
makefile
4
makefile
|
@ -11,8 +11,10 @@ update_all:
|
|||
git add --all
|
||||
git commit -m "Updated everything. Further explanation in README"
|
||||
git push -u origin main
|
||||
|
||||
update_domain:
|
||||
git add domain/
|
||||
git commit -m "Updated domain. Further explanation in README"
|
||||
git push -u origin main
|
||||
|
||||
fetch_git:
|
||||
git pull origin main
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -11,8 +11,10 @@ update_all:
|
|||
git add --all
|
||||
git commit -m "Updated everything. Further explanation in README"
|
||||
git push -u origin main
|
||||
|
||||
update_domain:
|
||||
git add domain/
|
||||
git commit -m "Updated domain. Further explanation in README"
|
||||
git push -u origin main
|
||||
|
||||
fetch_git:
|
||||
git pull origin main
|
Binary file not shown.
|
@ -1,7 +0,0 @@
|
|||
package robot.interfaces;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Sorting {
|
||||
int[] sorting(int[] input);
|
||||
|
||||
}
|
Loading…
Reference in New Issue