diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-01-06 11:43:01 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-01-06 11:43:01 +0100 |
| commit | c1a240e873cb0e434ea98506d2f33b4a571e354a (patch) | |
| tree | 71c6c90767a01a7b9b473f84ef54834c8f14b581 /src/de/fhswf/in/inf/java1/aufgabe12/BinaryOperator.java | |
| parent | 44d4f449ee2b072ec62618d6e1cfa2bd419c4f77 (diff) | |
| download | Java1-c1a240e873cb0e434ea98506d2f33b4a571e354a.tar.gz Java1-c1a240e873cb0e434ea98506d2f33b4a571e354a.zip | |
Assignment No.12 first complete implementation.
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe12/BinaryOperator.java')
| -rw-r--r-- | src/de/fhswf/in/inf/java1/aufgabe12/BinaryOperator.java | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe12/BinaryOperator.java b/src/de/fhswf/in/inf/java1/aufgabe12/BinaryOperator.java index ef007bd..50ac855 100644 --- a/src/de/fhswf/in/inf/java1/aufgabe12/BinaryOperator.java +++ b/src/de/fhswf/in/inf/java1/aufgabe12/BinaryOperator.java @@ -1,51 +1,51 @@ -/**
- *
- */
-package de.fhswf.in.inf.java1.aufgabe12;
-
-import java.util.Stack;
-
-/**
- * An abstract class for calculations with unary operators.
- *
- * @author $Author: $
- * @version $Revision: $, $Date: $ UTC
- */
-public abstract class BinaryOperator implements Operator
-{
- /*
- * (non-Javadoc)
- *
- * @see de.fhswf.in.inf.java1.aufgabe12.Operator#eval(java.util.Stack)
- */
- @Override
- public final void eval(Stack<Double> stack)
- {
- if (stack == null)
- {
- throw new IllegalArgumentException("Stack must not be null.");
- }
-
- if (stack.size() < 2)
- {
- throw new IllegalArgumentException(
- "Unary operation requires one operand.");
- }
-
- double d2 = stack.pop();
- double d1 = stack.pop();
-
- stack.push(eval(d1, d2));
- }
-
- /**
- * This class implements the calculation.
- *
- * @param d1
- * The first operator.
- * @param d2
- * The second operator.
- * @return The result of the calculation.
- */
- abstract double eval(double d1, double d2);
-}
+/** + * + */ +package de.fhswf.in.inf.java1.aufgabe12; + +import java.util.Stack; + +/** + * An abstract class for calculations with unary operators. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public abstract class BinaryOperator implements Operator +{ + /* + * (non-Javadoc) + * + * @see de.fhswf.in.inf.java1.aufgabe12.Operator#eval(java.util.Stack) + */ + @Override + public final void eval(Stack<Double> stack) + { + if (stack == null) + { + throw new IllegalArgumentException("Stack must not be null."); + } + + if (stack.size() < 2) + { + throw new IllegalArgumentException( + "Unary operation requires one operand."); + } + + double d2 = stack.pop(); + double d1 = stack.pop(); + + stack.push(eval(d1, d2)); + } + + /** + * This method implements the calculation. + * + * @param d1 + * The first operator. + * @param d2 + * The second operator. + * @return The result of the calculation. + */ + abstract double eval(double d1, double d2); +} |
