Updated everything. Further explanation in README

main
Philipp3107 2022-12-20 12:03:41 +01:00
parent 542ac31f89
commit b691e40c56
16 changed files with 112 additions and 75 deletions

View File

@ -1,18 +1,25 @@
import domain.C3PO; import domain.*;
import robot.exceptions.RobotException; import robot.exceptions.RobotException;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
C3PO Herbert = new C3PO(0, "Herbert");
R2D2 Gudrun = new R2D2(0, "Gdurun"); int[] input = {42,6,5,4,3,2,1};
int[] input = {6,5,4,3,2,1};
int[] input2 = input; int[] input2 = input;
C3PO Herbert = new C3PO(1, "Herbert");
R2D2 Herb = new R2D2(0, "Herb");
//Herbert.triggerPowerSwitch(); //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"); //System.out.println("Was neues ausgeben");
//just some testing //just some testing

View File

@ -1,20 +1,45 @@
package domain; package domain;
import robot.exceptions.RobotException; 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 class C3PO extends RobotBasics {
public C3PO(int id, String name){ public C3PO(int id, String name){
super(id, 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 @Override
public int[] think(int[] zahlen) throws RobotException { public String speak(int[] zahlen) throws RobotException {
return insertionSort.sorting(zahlen); //Insertionsort
if(isPowerOn()){
try{
return ausgabe(zahlen);
}catch(RobotException re){
return re.toString();
}
}else{
throw new RobotIllegalStateException(getName() + " is turned off.");
} }
Sorting insertionSort = (int[] input) ->{ }
System.out.println("ich sortiere mit insertion-Sort"); @Override
return input; public int[] think(int[] zahlen) throws RobotException {
}; return new int[0];
}
} }

View File

@ -3,17 +3,35 @@ package domain;
import robot.exceptions.RobotException; import robot.exceptions.RobotException;
import robot.exceptions.RobotIllegalStateException; 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 { 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){ public R2D2(int id, String name){
super(id, 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 { public int[] think(int[] zahlen) throws RobotException {
if(isPowerOn()){ if(isPowerOn()){
return sorting(zahlen); return sorting(zahlen);
@ -41,16 +59,15 @@ public class R2D2 extends RobotBasics {
return arr; return arr;
} }
public String ausgabe(int[] input){ // Diese ganze Methode muss zu C3P0 und ist hier falsch.
String result = " "; public String ausgabe(int[] input)throws RobotException{
if(input.length != 0) { if(input.length != 0 && !checkArray(input)) {
result = " " + input[0]; return Arrays.stream(input)
for(int i = 1; i < input.length; i++){ .mapToObj(Integer::toString)
result += "; " + input[i]; .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 @Override
public String speak(int[] input) throws RobotException { public String speak(int[] input) throws RobotException {
if(isPowerOn()){ final boolean[] found_42 = {false};
if (isPowerOn()) {
try{
return ausgabe(input); return ausgabe(input);
}else{ }catch(RobotException re){
throw new RobotIllegalStateException(getName() + " is turned off!"); return re.toString();
} }
} else {
throw new RobotIllegalStateException(getName() + " is turned off!");
}
/*public void something() {
System.out.println("Hello");
}*/
} }
} }

View File

@ -2,10 +2,7 @@ package domain;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class R2D2Test { class R2D2Test {
@ -21,6 +18,7 @@ class R2D2Test {
//Tests for basic functions //Tests for basic functions
@Test @Test
void getId() { void getId() {
assertEquals(id, Herbert.getId()); assertEquals(id, Herbert.getId());
} }

View File

@ -7,7 +7,7 @@ import robot.interfaces.Robot;
import java.util.Arrays; import java.util.Arrays;
public class RobotBasics implements Robot { public abstract class RobotBasics implements Robot {
private int id; private int id;
private String name; private String name;
private boolean power; private boolean power;
@ -38,10 +38,10 @@ public class RobotBasics implements Robot {
*/ */
@Override @Override
public void triggerPowerSwitch() { public void triggerPowerSwitch() {
if(power == false){ if(power){
power = true;
}else{
power = false; power = false;
}else{
power = true;
} }
} }
@ -61,32 +61,13 @@ public class RobotBasics implements Robot {
return null; return null;
} }
/** public boolean checkArray(int[] input){
* @see robot.interfaces.RobotInstructions; for(int x: input){
* Maybe method is depractable if(x == 42){
*/ return true;
@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.");
} }
} }
/** return false;
* @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");
}
} }
} }

View File

@ -1,4 +1,5 @@
package facade; package facade;
public class Factory { public class Factory {
} }

View File

@ -11,8 +11,10 @@ update_all:
git add --all git add --all
git commit -m "Updated everything. Further explanation in README" git commit -m "Updated everything. Further explanation in README"
git push -u origin main git push -u origin main
update_domain: 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
fetch_git:
git pull origin main

View File

@ -11,8 +11,10 @@ update_all:
git add --all git add --all
git commit -m "Updated everything. Further explanation in README" git commit -m "Updated everything. Further explanation in README"
git push -u origin main git push -u origin main
update_domain: 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
fetch_git:
git pull origin main

View File

@ -1,7 +0,0 @@
package robot.interfaces;
@FunctionalInterface
public interface Sorting {
int[] sorting(int[] input);
}