diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Software Architektur/SWA_Prakt1/src | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Master/Software Architektur/SWA_Prakt1/src')
8 files changed, 606 insertions, 0 deletions
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticAddition.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticAddition.java new file mode 100644 index 0000000..cac4983 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticAddition.java @@ -0,0 +1,130 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticAddition extends ArithmeticOperator {
+
+ public ArithmeticAddition(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operandSign="+";
+ }
+ @Override
+ public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() + num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() + num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() + num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() + num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() + num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() + num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() + num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() + num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() + num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() + num2.intValue();
+ }
+ return res;
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticDivision.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticDivision.java new file mode 100644 index 0000000..9545ec9 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticDivision.java @@ -0,0 +1,130 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticDivision extends ArithmeticOperator {
+
+ public ArithmeticDivision(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operandSign="/";
+ }
+
+ public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() / num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() / num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() / num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() / num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() / num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() / num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() / num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() / num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() / num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() / num2.intValue();
+ }
+ return res;
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticExpression.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticExpression.java new file mode 100644 index 0000000..1bb8351 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticExpression.java @@ -0,0 +1,6 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public interface ArithmeticExpression {
+ public void print();
+ public Number evaluate();
+}
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticMultiplication.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticMultiplication.java new file mode 100644 index 0000000..b9d147c --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticMultiplication.java @@ -0,0 +1,134 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticMultiplication extends ArithmeticOperator {
+
+
+
+ public ArithmeticMultiplication(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operandSign = "*";
+ }
+
+ @Override
+ public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() * num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() * num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() * num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() * num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() * num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() * num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() * num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() * num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() * num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() * num2.intValue();
+ }
+
+ return res;
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticOperator.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticOperator.java new file mode 100644 index 0000000..b460fd0 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticOperator.java @@ -0,0 +1,20 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public abstract class ArithmeticOperator implements ArithmeticExpression{
+ protected ArithmeticExpression operand1;
+ protected ArithmeticExpression operand2;
+ protected String operandSign;
+ public ArithmeticOperator(ArithmeticExpression operand1
+ ,ArithmeticExpression operand2){
+ this.operand1 = operand1;
+ this.operand2 = operand2;
+ }
+ @Override
+ public void print() {
+ System.out.print("(");
+ operand1.print();
+ System.out.print(operandSign);
+ operand2.print();
+ System.out.print(")");
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticRunner.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticRunner.java new file mode 100644 index 0000000..b3372f4 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticRunner.java @@ -0,0 +1,32 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticRunner {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ ArithmeticVariable a = new ArithmeticVariable("a", 2L);
+ ArithmeticVariable b = new ArithmeticVariable("b", 77);
+ ArithmeticVariable c = new ArithmeticVariable("c", 0.1f);
+ ArithmeticVariable d = new ArithmeticVariable("d", 0.00003d);
+
+ ArithmeticExpression aAddb = new ArithmeticAddition(a,b);
+ ArithmeticExpression aSubc = new ArithmeticSubstraction(a,c);
+ ArithmeticExpression bMuld = new ArithmeticMultiplication(b, d);
+
+ ArithmeticExpression ae1 = new ArithmeticMultiplication(aAddb, aSubc);
+ ArithmeticExpression ae2 = new ArithmeticSubstraction(bMuld, a);
+
+ ArithmeticExpression ae3 = new ArithmeticDivision(new ArithmeticAddition(ae1, ae2),new ArithmeticVariable("e", 100000));
+
+ try {
+ ae3.print();
+ System.out.println("\nResult: "+ae3.evaluate());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticSubstraction.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticSubstraction.java new file mode 100644 index 0000000..6f284c6 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticSubstraction.java @@ -0,0 +1,132 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticSubstraction extends ArithmeticOperator {
+
+ public ArithmeticSubstraction(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operandSign = "-";
+ }
+
+ @Override
+ public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() -num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() -num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() -num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() -num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() -num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() -num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() -num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() -num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() -num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() -num2.intValue();
+ }
+
+ return res;
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticVariable.java b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticVariable.java new file mode 100644 index 0000000..a3b931d --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt1/src/net/sven_eisenhauer/swa_prakt1/ArithmeticVariable.java @@ -0,0 +1,22 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticVariable implements ArithmeticExpression {
+
+ private String name;
+ private Number value;
+
+ public ArithmeticVariable(String name,Number value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ @Override
+ public Number evaluate() {
+ return value;
+ }
+
+ @Override
+ public void print() {
+ System.out.print(name);
+ }
+}
|
