~jozilla/uiml.net/uiml.net-tp

« back to all changes in this revision

Viewing changes to examples/CalcFunc.cs

  • Committer: kluyten
  • Date: 2004-06-20 23:10:09 UTC
  • Revision ID: vcs-imports@canonical.com-20040620231009-b9b2875161f3b250
*** empty log message ***

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
 
 
3
 
 
4
/// double implementation
 
5
class CalcFunc
 
6
{
 
7
        public static bool empty = true;
 
8
        public static double result = 0;
 
9
        public static double temp = 0;
 
10
        public static string sign = null;
 
11
        public static string operation = null;
 
12
 
 
13
        public static void RecordNumber(string number)
 
14
        {
 
15
                temp = Double.Parse(number);
 
16
                if(operation != null)
 
17
                {
 
18
                        result = Calculate(temp);
 
19
                        operation = null;
 
20
                }
 
21
                else
 
22
                        result = temp;
 
23
 
 
24
        }
 
25
 
 
26
        public static double Calculate(double g)
 
27
        {
 
28
                switch(operation)
 
29
                {
 
30
                        case "+":
 
31
                                return result + g;
 
32
                        case "-":
 
33
                                return result - g;
 
34
                        case "*":
 
35
                                return result * g;
 
36
                        case "/":
 
37
                                return result / g;              
 
38
                }
 
39
                return g;
 
40
        }
 
41
 
 
42
        public static void RecordSign(string psign)
 
43
        {
 
44
                sign = psign;
 
45
                result = temp;
 
46
        }
 
47
 
 
48
        public static void RecordOperation(string oper)
 
49
        {
 
50
                operation = oper;
 
51
        }
 
52
 
 
53
        public static string SwitchSign(String number)
 
54
        {
 
55
                return -Double.Parse(number) + "";
 
56
        }
 
57
 
 
58
 
 
59
        public static String CalculateResult()
 
60
        {
 
61
                sign = null;
 
62
           operation = null;
 
63
                empty = true;
 
64
                return "" + result;
 
65
        }
 
66
}