Program.cs 2.86 KB
Newer Older
Andres Käver's avatar
Andres Käver committed
1
2
3
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
Andres Käver's avatar
Andres Käver committed
4
5
using System.Xml;
using CalculatorBrain;
Andres Käver's avatar
Andres Käver committed
6
7
8
9
10
11
using MenuSystem;

namespace ConsoleApp
{
    class Program
    {
Andres Käver's avatar
Andres Käver committed
12
13
14

        private static readonly Brain Brain = new Brain();
        
Andres Käver's avatar
menu    
Andres Käver committed
15
        
Andres Käver's avatar
Andres Käver committed
16
17
18
19
        static void Main(string[] args)
        {
            Console.Clear();

Andres Käver's avatar
menu    
Andres Käver committed
20

Andres Käver's avatar
Andres Käver committed
21
            var mainMenu = new Menu(ReturnCurrentDisplayValue, "Calculator Main", EMenuLevel.Root);
Andres Käver's avatar
menu    
Andres Käver committed
22
            mainMenu.AddMenuItems(new List<MenuItem>()
Andres Käver's avatar
Andres Käver committed
23
            {
Andres Käver's avatar
menu    
Andres Käver committed
24
25
                new MenuItem("A", "Binary operations", SubmenuBinary),
                new MenuItem("S", "Unary operations", SubmenuUnary),
Andres Käver's avatar
menu    
Andres Käver committed
26
            });
Andres Käver's avatar
Andres Käver committed
27

Andres Käver's avatar
Andres Käver committed
28
            mainMenu.Run();
Andres Käver's avatar
menu    
Andres Käver committed
29
        }
Andres Käver's avatar
menu    
Andres Käver committed
30

Andres Käver's avatar
Andres Käver committed
31
32
33
34
35
        public static string ReturnCurrentDisplayValue()
        {
            return Brain.CurrentValue.ToString();
        }

Andres Käver's avatar
menu    
Andres Käver committed
36
37
38
39
        public static string MethodA()
        {
            Console.WriteLine("Method A!!!!!");
            return "";
Andres Käver's avatar
Andres Käver committed
40
41
        }

Andres Käver's avatar
menu    
Andres Käver committed
42
        public static string SubmenuBinary()
Andres Käver's avatar
Andres Käver committed
43
        {
Andres Käver's avatar
Andres Käver committed
44
            var menu = new Menu(ReturnCurrentDisplayValue, "Binary", EMenuLevel.First);
Andres Käver's avatar
menu    
Andres Käver committed
45
            menu.AddMenuItems(new List<MenuItem>()
Andres Käver's avatar
Andres Käver committed
46
            {
Andres Käver's avatar
menu    
Andres Käver committed
47
48
49
                new MenuItem("+", "+", Add),
                new MenuItem("-", "-", MethodA),
                new MenuItem("/", "/", MethodA),
Andres Käver's avatar
Andres Käver committed
50
                new MenuItem("*", "*", Multiplication),
Andres Käver's avatar
menu    
Andres Käver committed
51
52
53
54
            });
            var res = menu.Run();
            return res;
        }
Andres Käver's avatar
Andres Käver committed
55

Andres Käver's avatar
Andres Käver committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        public static string Multiplication()
        {
            Console.WriteLine("Current value: " + Brain.CurrentValue);
            Console.WriteLine("multiply");
            Console.Write("number: ");
            var n = Console.ReadLine()?.Trim();
            double.TryParse(n, out var converted);

            //Brain.ApplyCustomFunction( CustomMultiply, converted);
            Brain.ApplyCustomFunction( (a,  b) => a * b, converted);
            return "";
        }

        public static double CustomMultiply(double a , double b)
        {
            return a * b;
        }

Andres Käver's avatar
menu    
Andres Käver committed
74
75
76
        public static string Add()
        {
            // CalculatorCurrentDisplay
Andres Käver's avatar
Andres Käver committed
77
            Console.WriteLine("Current value: " + Brain.CurrentValue);
Andres Käver's avatar
menu    
Andres Käver committed
78
79
80
81
82
            Console.WriteLine("plus");
            Console.Write("number: ");
            var n = Console.ReadLine()?.Trim();
            double.TryParse(n, out var converted);

Andres Käver's avatar
Andres Käver committed
83
84
            Brain.Add(converted);

Andres Käver's avatar
menu    
Andres Käver committed
85
86
87
88
89
            return "";
        }

        public static string SubmenuUnary()
        {
Andres Käver's avatar
Andres Käver committed
90
            var menu = new Menu(ReturnCurrentDisplayValue, "Unary", EMenuLevel.First);
Andres Käver's avatar
menu    
Andres Käver committed
91
92
93
94
95
96
97
98
            menu.AddMenuItems(new List<MenuItem>()
            {
                new MenuItem("Negate", "Negate", MethodA),
                new MenuItem("Sqrt", "Sqrt", MethodA),
                new MenuItem("Root", "Root", MethodA),
            });
            var res = menu.Run();
            return res;
Andres Käver's avatar
Andres Käver committed
99
100
101
        }
    }
}