verwendung von Robotinstanzen vermieden, Anwendungsmenü aktualisiert
parent
0f4c343fce
commit
7d8237bf76
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
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.
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.
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.
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.
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.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -7,7 +7,6 @@ import utility.robot_exceptions.robotExceptions;
|
||||||
public class C3PO extends Robot {
|
public class C3PO extends Robot {
|
||||||
public C3PO(int id, String name){
|
public C3PO(int id, String name){
|
||||||
super(id, name, RobotType.C3PO);
|
super(id, name, RobotType.C3PO);
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param input from the user
|
* @param input from the user
|
||||||
|
|
|
@ -41,7 +41,9 @@ public class Factory implements Serializable {
|
||||||
r = new R2D2(r2d2ID++, name);
|
r = new R2D2(r2d2ID++, name);
|
||||||
} else if(type == RobotType.C3PO) {
|
} else if(type == RobotType.C3PO) {
|
||||||
r = new C3PO(c3poID++, name);
|
r = new C3PO(c3poID++, name);
|
||||||
} else {
|
}else if(type == RobotType.Nexus6){
|
||||||
|
r = new Nexus6("Pris");
|
||||||
|
}else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,9 +99,11 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable {
|
||||||
*/
|
*/
|
||||||
public String output(int[] input, String delemiter)throws RobotException{
|
public String output(int[] input, String delemiter)throws RobotException{
|
||||||
if(checkArray(input)) {
|
if(checkArray(input)) {
|
||||||
return Arrays.stream(input)
|
final String[] msg = {""};
|
||||||
.mapToObj(Integer::toString)
|
Arrays.stream(input).forEach(s -> {
|
||||||
.collect(Collectors.joining(delemiter + " "));
|
msg[0] += s + delemiter + " ";
|
||||||
|
});
|
||||||
|
return msg[0];
|
||||||
}else{
|
}else{
|
||||||
RobotException robotexception = new RobotException(robotExceptions.MAGICVALUE, getName());
|
RobotException robotexception = new RobotException(robotExceptions.MAGICVALUE, getName());
|
||||||
this.exceptions = new ExceptionStorage(robotexception);
|
this.exceptions = new ExceptionStorage(robotexception);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import domain.Factory;
|
||||||
import domain.Robot;
|
import domain.Robot;
|
||||||
import domain.RobotType;
|
import domain.RobotType;
|
||||||
import infrastructure.Persistenz;
|
import infrastructure.Persistenz;
|
||||||
|
import utility.robot_exceptions.RobotException;
|
||||||
|
|
||||||
public class FactorySystem {
|
public class FactorySystem {
|
||||||
private Factory factory;
|
private Factory factory;
|
||||||
|
@ -22,6 +23,7 @@ public class FactorySystem {
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
this.factory = new Factory();
|
this.factory = new Factory();
|
||||||
|
boolean pris = buildNewRobot("Pris", RobotType.Nexus6);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,11 +38,7 @@ public class FactorySystem {
|
||||||
public boolean buildNewRobot(String name, RobotType type) {
|
public boolean buildNewRobot(String name, RobotType type) {
|
||||||
boolean check = factory.buildNewRobot(name, type);
|
boolean check = factory.buildNewRobot(name, type);
|
||||||
if(check) {
|
if(check) {
|
||||||
try {
|
saveFactroyData();
|
||||||
Persistenz.saveFactoryData(factory, factoryName);
|
|
||||||
}catch(Exception e){
|
|
||||||
System.out.println(e.getCause());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return check;
|
return check;
|
||||||
}
|
}
|
||||||
|
@ -53,4 +51,37 @@ public class FactorySystem {
|
||||||
return factory.getRobotOfList(id);
|
return factory.getRobotOfList(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String letRobotSpeak(int[] input, int id){
|
||||||
|
|
||||||
|
String output = "";
|
||||||
|
try{
|
||||||
|
output = factory.getRobotOfList(id).speak(input);
|
||||||
|
}catch(RobotException re){
|
||||||
|
saveFactroyData();
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] letRobotThink(int[] input, int id){
|
||||||
|
int[] unsorted = new int[input.length];
|
||||||
|
try{
|
||||||
|
unsorted = factory.getRobotOfList(id).think(input);
|
||||||
|
}catch(RobotException re){
|
||||||
|
saveFactroyData();
|
||||||
|
}
|
||||||
|
return unsorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RobotException getExceptions(int id){
|
||||||
|
return factory.getRobotOfList(id).getLastException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFactroyData(){
|
||||||
|
try {
|
||||||
|
Persistenz.saveFactoryData(factory, factoryName);
|
||||||
|
}catch(Exception e){
|
||||||
|
System.out.println(e.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,43 +125,54 @@ public class UI {
|
||||||
mainloop:
|
mainloop:
|
||||||
while(true) {
|
while(true) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("_______________________________");
|
System.out.println("____________________________________");
|
||||||
System.out.println("Sie haben folgende optionen: ");
|
System.out.println("--- Sie haben folgende optionen: ---");
|
||||||
System.out.println("-1- --- Roboter " + (!fs.searchForRobot(idInput).isPowerOn() ? "Einschalten " : "Ausschalten " ) + " ---");
|
System.out.println("-1- ----- Roboter " + (!fs.searchForRobot(idInput).isPowerOn() ? "Einschalten " : "Ausschalten " ) + " -----");
|
||||||
System.out.println("-2- -- Sortieren einer Liste --");
|
System.out.println("-2- ---- Sortieren einer Liste -----");
|
||||||
System.out.println("-3- ----- Namen ausgeben ------");
|
System.out.println("-3- ------- Namen ausgeben ---------");
|
||||||
System.out.println("-4- ------ ID ausgeben --------");
|
System.out.println("-4- --------- ID ausgeben ----------");
|
||||||
System.out.println("-5- ------ Typ ausgeben -------");
|
System.out.println("-5- -------- Typ ausgeben ----------");
|
||||||
System.out.println("-6- ---------- Exit -----------");
|
System.out.println("-6- - letzte Fehlermeldung anzeigen -");
|
||||||
|
System.out.println("-7- ------------- Exit --------------");
|
||||||
System.out.print(" > ");
|
System.out.print(" > ");
|
||||||
//User options
|
//User options
|
||||||
try {
|
try {
|
||||||
int input = Integer.parseInt(sc.nextLine());
|
int input = Integer.parseInt(sc.nextLine());
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case 1:
|
case 1 -> {
|
||||||
fs.searchForRobot(idInput).triggerPowerSwitch();
|
fs.searchForRobot(idInput).triggerPowerSwitch();
|
||||||
System.out.println("Der Roboter hat seinen Zustand gewechselt");
|
System.out.println("Der Roboter hat seinen Zustand gewechselt");
|
||||||
break;
|
}
|
||||||
case 2:
|
case 2 -> {
|
||||||
int[] unsortedList = null;
|
int[] unsortedList = null;
|
||||||
while(unsortedList == null) {
|
while (unsortedList == null) {
|
||||||
try {
|
try {
|
||||||
unsortedList = fs.searchForRobot(idInput).think(Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray());
|
unsortedList = fs.letRobotThink(Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray(), idInput);
|
||||||
System.out.println(fs.searchForRobot(idInput).speak(unsortedList));
|
System.out.println(fs.letRobotSpeak(unsortedList, idInput));
|
||||||
} catch (NumberFormatException | RobotException e) {
|
} catch (NumberFormatException nfe) {
|
||||||
if(e.getClass() == RobotException.class){
|
|
||||||
System.out.println(((RobotException) e).getMessage());
|
|
||||||
break;
|
|
||||||
}else{
|
|
||||||
System.out.println("Falsches Format versuch es erneut");
|
System.out.println("Falsches Format versuch es erneut");
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 6: break mainloop;
|
case 3 -> System.out.println("Mein Name lautet " + fs.searchForRobot(idInput).getName() + ".");
|
||||||
default:
|
case 4 -> System.out.println("Meine ID ist " + fs.searchForRobot(idInput).getId() + ".");
|
||||||
System.out.println("Keine valide Option"); break;
|
case 5 -> System.out.println("Meine Typ ist " + fs.searchForRobot(idInput).getType().toString() + ".");
|
||||||
|
|
||||||
|
case 6 -> {
|
||||||
|
try{
|
||||||
|
String message = fs.getExceptions(idInput).getMessage();
|
||||||
|
System.out.println("Letze Fehlermeldung: ");
|
||||||
|
System.out.println(message);
|
||||||
|
}catch(NullPointerException npe){
|
||||||
|
System.out.println("Bisher keine Fehlermeldung vorhanden.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 7 -> {
|
||||||
|
break mainloop;
|
||||||
|
}
|
||||||
|
|
||||||
|
default -> System.out.println("Keine valide Option");
|
||||||
|
|
||||||
}
|
}
|
||||||
}catch(NumberFormatException nfe) {
|
}catch(NumberFormatException nfe) {
|
||||||
System.out.println("Kein valider input");
|
System.out.println("Kein valider input");
|
||||||
|
|
|
@ -1,25 +1,12 @@
|
||||||
package utility.robot_exceptions;
|
package utility.robot_exceptions;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
public class ExceptionStorage implements Serializable {
|
public class ExceptionStorage implements Serializable {
|
||||||
private RobotException message;
|
private RobotException message;
|
||||||
private LocalDateTime date;
|
|
||||||
|
|
||||||
public ExceptionStorage(RobotException message){
|
public ExceptionStorage(RobotException message){
|
||||||
this.message = message;
|
this.message = message;
|
||||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
this.date = now;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param message of the exception
|
|
||||||
*/
|
|
||||||
public void saveLatestErrorMessage(RobotException message){
|
|
||||||
this.message = message;
|
|
||||||
this.date = LocalDateTime.now();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RobotException getLastErrorMessage(){
|
public RobotException getLastErrorMessage(){
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package utility.robot_exceptions;
|
package utility.robot_exceptions;
|
||||||
|
|
||||||
|
import facade.FactorySystem;
|
||||||
|
import infrastructure.Persistenz;
|
||||||
|
|
||||||
public class RobotException extends Exception{
|
public class RobotException extends Exception{
|
||||||
robotExceptions currentType;
|
robotExceptions currentType;
|
||||||
String name;
|
String name;
|
||||||
|
|
Binary file not shown.
|
@ -40,7 +40,7 @@ class C3POTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void speak(){
|
void speak(){
|
||||||
String solution = "12; 2; 4; 5; 12; 2; 4; 7; 56; 433; 23";
|
String solution = "12; 2; 4; 5; 12; 2; 4; 7; 56; 433; 23; ";
|
||||||
int[] input = {12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23};
|
int[] input = {12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23};
|
||||||
String array = "";
|
String array = "";
|
||||||
try{
|
try{
|
||||||
|
@ -53,7 +53,7 @@ class C3POTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void C3POSpeakTestStandard() throws RobotException {
|
void C3POSpeakTestStandard() throws RobotException {
|
||||||
assertEquals("1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12", c3po.speak(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}));
|
assertEquals("1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; ", c3po.speak(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -67,17 +67,17 @@ class C3POTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void C3POSpeakTestZeros() throws RobotException {
|
void C3POSpeakTestZeros() throws RobotException {
|
||||||
assertEquals("0; 0; 0; 0", c3po.speak(new int[4]));
|
assertEquals("0; 0; 0; 0; ", c3po.speak(new int[4]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void C3POSpeakTestOneElement() throws RobotException {
|
void C3POSpeakTestOneElement() throws RobotException {
|
||||||
assertEquals("1", c3po.speak(new int[]{1}));
|
assertEquals("1; ", c3po.speak(new int[]{1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void C3POSpeakTestUnitElements() throws RobotException {
|
void C3POSpeakTestUnitElements() throws RobotException {
|
||||||
assertEquals("-1; 0; 1", c3po.speak(new int[]{-1, 0, 1}));
|
assertEquals("-1; 0; 1; ", c3po.speak(new int[]{-1, 0, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package tests;
|
package tests;
|
||||||
|
|
||||||
import domain.Nexus6;
|
import domain.Nexus6;
|
||||||
import domain.R2D2;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import utility.robot_exceptions.RobotException;
|
import utility.robot_exceptions.RobotException;
|
||||||
|
|
|
@ -38,7 +38,7 @@ class R2D2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void R2D2SpeakTestStandard() throws RobotException {
|
void R2D2SpeakTestStandard() throws RobotException {
|
||||||
assertEquals("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12", r2d2.speak(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}));
|
assertEquals("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ", r2d2.speak(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,17 +52,17 @@ class R2D2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void R2D2SpeakTestZeros() throws RobotException {
|
void R2D2SpeakTestZeros() throws RobotException {
|
||||||
assertEquals("0, 0, 0, 0", r2d2.speak(new int[4]));
|
assertEquals("0, 0, 0, 0, ", r2d2.speak(new int[4]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void R2D2SpeakTestOneElement() throws RobotException {
|
void R2D2SpeakTestOneElement() throws RobotException {
|
||||||
assertEquals("1", r2d2.speak(new int[]{1}));
|
assertEquals("1, ", r2d2.speak(new int[]{1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void R2D2SpeakTestUnitElements() throws RobotException {
|
void R2D2SpeakTestUnitElements() throws RobotException {
|
||||||
assertEquals("-1, 0, 1", r2d2.speak(new int[]{-1, 0, 1}));
|
assertEquals("-1, 0, 1, ", r2d2.speak(new int[]{-1, 0, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -76,7 +76,7 @@ class R2D2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void speak(){
|
void speak(){
|
||||||
String solution = "12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23";
|
String solution = "12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23, ";
|
||||||
int[] input = {12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23};
|
int[] input = {12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23};
|
||||||
String array = "";
|
String array = "";
|
||||||
try{
|
try{
|
||||||
|
|
Loading…
Reference in New Issue