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;
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

View File

@ -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;
};
}

View File

@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.*;
class C3POTest {
C3PO Herbert;
C3PO Herbert;
int id = 0;
String name = "Herbert";

View File

@ -3,20 +3,38 @@ 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);
return sorting(zahlen);
}else{
throw new RobotIllegalStateException(getName() + " is turned off!");
}
@ -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];
}
return result;
// 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 null;
}
/**
@ -61,10 +78,21 @@ public class R2D2 extends RobotBasics {
*/
@Override
public String speak(int[] input) throws RobotException {
if(isPowerOn()){
return ausgabe(input);
}else{
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");
}*/
}
}

View File

@ -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());
}

View File

@ -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;
}
}

View File

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

View File

@ -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
git push -u origin main
fetch_git:
git pull origin main

View File

@ -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
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);
}