From 03fc5b97128bf3383bc4328d9eb7471fafef3a61 Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Wed, 6 Apr 2022 23:54:20 +0200 Subject: [PATCH] =?UTF-8?q?Operatoren=20+=20und=20*=20hinzugef=C3=BCgt=20i?= =?UTF-8?q?n=20Aufgabe1=5FKellerautomat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/Aufgabe1_KellerautomatTest.java | 4 ++-- src/Aufgabe1_Kellerautomat.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Test/Aufgabe1_KellerautomatTest.java b/Test/Aufgabe1_KellerautomatTest.java index ae511ad..e8f69bb 100644 --- a/Test/Aufgabe1_KellerautomatTest.java +++ b/Test/Aufgabe1_KellerautomatTest.java @@ -6,12 +6,12 @@ class Aufgabe1_KellerautomatTest { @Test void calculate() { - String[] acceptableWords = {"ZZO", "ZZOZZOO", "ZZZOO"}; + String[] acceptableWords = {"ZZ+", "ZZ*ZZ+*", "ZZZ*+"}; for (String word : acceptableWords) { assertTrue(Aufgabe1_Kellerautomat.calculate(word)); } - String[] notAcceptableWords = {"ZZOO", "ZZOZZO", "ZOZ"}; + String[] notAcceptableWords = {"ZZ*+", "ZZ+ZZ*", "Z*Z"}; for (String word : notAcceptableWords) { assertFalse(Aufgabe1_Kellerautomat.calculate(word)); } diff --git a/src/Aufgabe1_Kellerautomat.java b/src/Aufgabe1_Kellerautomat.java index 41ff12c..e799a0a 100644 --- a/src/Aufgabe1_Kellerautomat.java +++ b/src/Aufgabe1_Kellerautomat.java @@ -48,7 +48,7 @@ public class Aufgabe1_Kellerautomat { break; case 2: symbol = wordChars.remove(0); - if (symbol == 'O' && stackSymbol == 'Z') { + if (isOperator(symbol) && stackSymbol == 'Z') { state = 3; } else if (symbol == 'Z' && stackSymbol == 'Z') { stack.add('Z'); @@ -79,7 +79,7 @@ public class Aufgabe1_Kellerautomat { stack.add('Z'); stack.add('Z'); state = 2; - } else if (symbol == 'O' && stackSymbol == 'Z') { + } else if (isOperator(symbol) && stackSymbol == 'Z') { state = 3; } else { dontAccept(word); @@ -121,4 +121,8 @@ public class Aufgabe1_Kellerautomat { System.out.println("Word: " + word + "\naccepted "); } + private static boolean isOperator(char symbol){ + return symbol == '+' || symbol == '*'; + } + }