From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/DSALib/Auxiliary/Calculator/Operator.cs | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dsa/DSALib/Auxiliary/Calculator/Operator.cs (limited to 'dsa/DSALib/Auxiliary/Calculator/Operator.cs') diff --git a/dsa/DSALib/Auxiliary/Calculator/Operator.cs b/dsa/DSALib/Auxiliary/Calculator/Operator.cs new file mode 100644 index 0000000..e6aeec6 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Calculator/Operator.cs @@ -0,0 +1,51 @@ +using System; +using DSALibv.Auxiliary.Calculator; + +namespace DSALib.Auxiliary.Calculator +{ + /// + /// The Operator Class represents a binary operator with tow Arguments and an Operation type + /// + public class Operator : ISolvable + { + private readonly ISolvable arg1, arg2; + + public Operator(ISolvable arg1, ISolvable arg2, Ops operatorType) + { + this.arg1 = arg1; + this.arg2 = arg2; + OperatorType = operatorType; + } + + public Ops OperatorType { get; set; } + + public int Solve() + { + int result; + switch (OperatorType) + { + case Ops.Dice: + result = Dice.Roll(arg1.Solve(), arg2.Solve()); + break; + case Ops.Multiply: + result = arg1.Solve() * arg2.Solve(); + break; + case Ops.Add: + result = arg1.Solve() + arg2.Solve(); + break; + case Ops.Subtract: + result = arg1.Solve() - arg2.Solve(); + break; + default: + throw new ArgumentOutOfRangeException(); + } + + return result; + } + + public override string ToString() + { + return $"({arg1} {OperatorType} {arg2})"; + } + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf