public void EquilateralTest(int sideLength, double area, double perimeter)
        {
            Equilateral equilateral = new Equilateral(sideLength);

            Assert.AreEqual(area, Math.Round(equilateral.GetArea(), 2));
            Assert.AreEqual(perimeter, Math.Round(equilateral.GetPerimeter(), 2));
        }
Beispiel #2
0
        /// <summary>
        /// Query a regression algorithm using equilateral encoding.
        /// </summary>
        /// <param name="alg">The algorithm being used.</param>
        /// <param name="theTrainingData">The training data.</param>
        /// <param name="items">The category items classified.</param>
        /// <param name="high">The high value.</param>
        /// <param name="low">The low value.</param>
        public static void QueryEquilateral(
            IRegressionAlgorithm alg,
            IList <BasicData> theTrainingData,
            IDictionary <String, int> items,
            double high, double low)
        {
            // first, we need to invert the items.  Right now it maps from category to index.  We need index to category.
            IDictionary <int, String> invMap = new Dictionary <int, string>();

            foreach (string key in items.Keys)
            {
                int value = items[key];
                invMap[value] = key;
            }

            // now we can query
            Equilateral eq = new Equilateral(items.Count, high, low);

            foreach (BasicData data in theTrainingData)
            {
                double[] output      = alg.ComputeRegression(data.Input);
                int      idealIndex  = eq.Decode(data.Ideal);
                int      actualIndex = eq.Decode(output);
                Console.WriteLine(VectorUtil.DoubleArrayToString(data.Input) + " -> " + invMap[actualIndex]
                                  + ", Ideal: " + invMap[idealIndex]);
            }
        }
Beispiel #3
0
        public void TestEncode()
        {
            var eq = new Equilateral(3, -1, 1);

            double[] d = eq.Encode(1);
            Assert.AreEqual(0.8660254037844386, d[0], AIFH.DefaultPrecision);
            Assert.AreEqual(-0.5, d[1], AIFH.DefaultPrecision);
        }
Beispiel #4
0
        public void iShapeCalc_test_Equilateral(double side1, double areaExpected, double perExpected)
        {
            var equil     = new Equilateral("red", side1);
            var equilArea = equil.GetArea(side1);
            var equilPer  = equil.GetPerimeter(side1);

            Assert.AreEqual(areaExpected, equilArea);
            Assert.AreEqual(perExpected, equilPer);
        }
Beispiel #5
0
        public void TEST_GetEquilateralTypeName_GIVEN_InheritTriangle_THEN_ItReturnsEquilateral()
        {
            // Arrange
            Triangle target         = new Equilateral(3, 3, 3);
            string   expectedResult = (typeof(Equilateral)).Name.ToString();

            // Act

            // Asset
            Assert.AreEqual(target.TypeName, expectedResult);
        }
Beispiel #6
0
        public void TestDecode()
        {
            var eq = new Equilateral(3, -1, 1);

            double[] d0 = { 0.866, 0.5 };
            double[] d1 = { -0.866, 0.5 };
            double[] d2 = { 0, -1 };
            Assert.AreEqual(2, eq.Decode(d0));
            Assert.AreEqual(2, eq.Decode(d1));
            Assert.AreEqual(0, eq.Decode(d2));
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Square square = new Square(5);

            Console.WriteLine($"{square}");
            Rectangle rectangle = new Rectangle(3, 6);

            Console.WriteLine($"{rectangle}");
            Equilateral eqTri = new Equilateral(4);

            Console.WriteLine($"{eqTri}");
            Right rTri = new Right(3, 4, 5);

            Console.WriteLine($"{rTri}");
        }
Beispiel #8
0
        public void Evaluate(FileInfo networkFile, FileInfo analystFile, FileInfo EvaluationFile)
        {
            var network = EncogDirectoryPersistence.LoadObject(networkFile) as BasicNetwork;
            var analyst = new EncogAnalyst();

            analyst.Load(analystFile);

            var evaluationSet = EncogUtility.LoadCSV2Memory(EvaluationFile.ToString(), network.InputCount,
                                                            network.OutputCount, true, CSVFormat.English, false);

            int count        = 0;
            int correctCount = 0;

            foreach (var item in evaluationSet)
            {
                var sepal_l = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(item.Input[0]);
                var sepal_w = analyst.Script.Normalize.NormalizedFields[1].DeNormalize(item.Input[1]);
                var petal_l = analyst.Script.Normalize.NormalizedFields[2].DeNormalize(item.Input[2]);
                var petal_w = analyst.Script.Normalize.NormalizedFields[3].DeNormalize(item.Input[3]);

                int classCount = analyst.Script.Normalize.NormalizedFields[4].Classes.Count;

                double normalizationHigh = analyst.Script.Normalize.NormalizedFields[4].NormalizedHigh;
                double normalizationLow  = analyst.Script.Normalize.NormalizedFields[4].NormalizedLow;

                var output            = network.Compute(item.Input);
                var resulter          = new Equilateral(classCount, normalizationHigh, normalizationLow);
                var predictedClassInt = resulter.Decode(output);
                var predictedClass    = analyst.Script.Normalize.NormalizedFields[4].Classes[predictedClassInt].Name;

                var idealClassInt = resulter.Decode(item.Ideal);
                var idealClass    = analyst.Script.Normalize.NormalizedFields[4].Classes[idealClassInt].Name;

                if (predictedClassInt == idealClassInt)
                {
                    ++correctCount;
                }

                Console.WriteLine($"Count: {++count} | Ideal: {idealClass} Predicted:{predictedClass}");
            }

            Console.WriteLine($"Total test count: {count}");
            Console.WriteLine($"Total correct test count: {correctCount}");
            Console.WriteLine($"% Success: {(correctCount*100.0)/count}");
        }
Beispiel #9
0
        /// <summary>
        /// Determine which item's index is the value.
        /// </summary>
        public override void RowInit()
        {
            for (int i = 0; i < this.items.Count; i++)
            {
                NominalItem item = this.items[i];
                if (item.IsInRange())
                {
                    this.currentValue = i;
                    break;
                }
            }

            if (this.equilateral == null)
            {
                this.equilateral = new Equilateral(this.items.Count, this.high,
                                                   this.low);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Determine which item's index is the value.
        /// </summary>
        public override void RowInit()
        {
            for (int i = 0; i < _items.Count; i++)
            {
                NominalItem item = _items[i];
                if (item.IsInRange())
                {
                    _currentValue = i;
                    break;
                }
            }

            if (_equilateral == null)
            {
                _equilateral = new Equilateral(_items.Count, _high,
                                               _low);
            }
        }
Beispiel #11
0
        public void Initial()
        {
            sq1 = new Square(5, "Blue");
            re1 = new Rectangle(5, 10, "Blue");
            eq1 = new Equilateral(5, "Blue");
            ri1 = new Rightangle(5, 10, "Blue");
            ci1 = new Circle(5, "Blue");

            sq2 = new Square(15, "Blue");
            re2 = new Rectangle(4, 6, "Blue");
            eq2 = new Equilateral(15, "Blue");
            ri2 = new Rightangle(4, 6, "Blue");
            ci2 = new Circle(15, "Blue");

            sq3 = new Square(7, "Blue");
            re3 = new Rectangle(9, 7, "Blue");
            eq3 = new Equilateral(7, "Blue");
            ri3 = new Rightangle(9, 7, "Blue");
            ci3 = new Circle(7, "Blue");
        }
 private ArrayList GetAllDistancesList()
 {
     var eq = new Equilateral(categories);
     var input = eq.Result;
     var n = input.Length;
     var results = new ArrayList();
     for (int x = 0; x < n - 1; x++)
     {
         for (int z = x + 1; z < n; z++)
         {
             double sum = 0;
             for (int y = 0; y < n - 1; y++)
             {
                 sum += Math.Pow(input[z][y] - input[x][y], 2);
             }
             results.Add(Math.Sqrt(sum));
         }
     }
     return results;
 }
        /// <summary>
        /// Init any internal structures.
        /// </summary>
        ///
        public void Init()
        {
            if (_action == NormalizationAction.Equilateral)
            {
                if (_classes.Count < Equilateral.MinEq)
                {
                    throw new QuantError("There must be at least three classes "
                                         + "to make use of equilateral normalization.");
                }

                _eq = new Equilateral(_classes.Count, _normalizedHigh,
                                      _normalizedLow);
            }

            // build lookup map
            foreach (ClassItem t in _classes)
            {
                _lookup[t.Name] = t.Index;
            }
        }
Beispiel #14
0
        /// <summary>
        /// Init any internal structures.
        /// </summary>
        ///
        public void Init()
        {
            if (_action == NormalizationAction.Equilateral)
            {
                if (_classes.Count < MinEqClasses)
                {
                    throw new QuantError(
                              "There must be at least three classes to make "
                              + "use of equilateral normalization.");
                }

                _eq = new Equilateral(_classes.Count, _normalizedHigh,
                                      _normalizedLow);
            }

            // build lookup map
            for (int i = 0; i < _classes.Count; i++)
            {
                _lookup[_classes[i].Name] = _classes[i].Index;
            }
        }
Beispiel #15
0
        public void Init()
        {
            s1 = new Square("white", 5);
            s2 = new Square("white", 15);
            s3 = new Square("white", 7);

            r1 = new Rectangle("white", 5, 10);
            r2 = new Rectangle("white", 4, 6);
            r3 = new Rectangle("white", 9, 7);

            c1 = new Circle("White", 5);
            c2 = new Circle("White", 15);
            c3 = new Circle("White", 7);

            e1 = new Equilateral("White", 5);
            e2 = new Equilateral("White", 15);
            e3 = new Equilateral("White", 7);

            ra1 = new RightAngle("White", 5, 10);
            ra2 = new RightAngle("White", 4, 6);
            ra3 = new RightAngle("White", 9, 7);
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("------This is Shape Gernerater-------");
            Console.WriteLine("Type [A] to create Square");
            Console.WriteLine("Type [B] to create Rectangle");
            Console.WriteLine("Type [C] to create Equailateral Triangle");
            Console.WriteLine("Type [D] to create RightAngle Triangle");
            Console.WriteLine("Type [E] to create Circle");


            string inputshape = Console.ReadLine().ToUpper();

            try
            {
                if (inputshape == "A")
                {
                    Console.WriteLine("You Selected Square, Please Type color for the shape");
                    string sqcolor = Console.ReadLine();
                    try
                    {
                        Console.WriteLine("Please Type side lenght for the square");
                        int sqside1 = int.Parse(Console.ReadLine());

                        if (sqside1 < 1)
                        {
                            throw new LessThanOneExecption();
                        }

                        Square sq = new Square(Convert.ToDouble(sqside1), sqcolor);

                        Console.WriteLine("Your created a " + sqcolor + " Square with Sidelength: " + sqside1);
                    }

                    catch (LessThanOneExecption e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Side Length cannot be less than 1");
                    }

                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Integer only for Side Length");
                    }
                }

                else if (inputshape == "B")
                {
                    Console.WriteLine("You Selected Rectangle, Please Type color for the shape");
                    string recolor = Console.ReadLine();
                    try
                    {
                        Console.WriteLine("Please Type side lenght 1 for the Rectangle");
                        int reside1 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Please Type side lenght 2 for the Rectangle");
                        int reside2 = int.Parse(Console.ReadLine());


                        Console.WriteLine();

                        if (reside1 < 1 || reside2 < 1)
                        {
                            throw new LessThanOneExecption();
                        }



                        Rectangle re = new Rectangle(Convert.ToDouble(reside1), Convert.ToDouble(reside2), recolor);

                        Console.WriteLine("Your created a " + recolor + " Rectangle with Sidelength1: " + reside1 + " and Sidekenght2: " + reside2);
                    }

                    catch (LessThanOneExecption e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Side Length cannot be less than 1");
                    }

                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Integer only for Side Length");
                    }
                }

                else if (inputshape == "C")
                {
                    Console.WriteLine("You Selected Equailateral Triangle, Please Type color for the shape");
                    string eqcolor = Console.ReadLine();
                    try
                    {
                        Console.WriteLine("Please Type side lenght for the Equailateral Triangle");
                        int eqside1 = int.Parse(Console.ReadLine());

                        if (eqside1 < 1)
                        {
                            throw new LessThanOneExecption();
                        }

                        Equilateral seq = new Equilateral(Convert.ToDouble(eqside1), eqcolor);

                        Console.WriteLine("Your created a " + eqcolor + " Equailateral Triangle with Sidelength: " + eqside1);
                    }

                    catch (LessThanOneExecption e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Side Length cannot be less than 1");
                    }

                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Integer only for Side Length");
                    }
                }

                else if (inputshape == "D")
                {
                    Console.WriteLine("You Selected RightAngle Triangle, Please Type color for the shape");
                    string ricolor = Console.ReadLine();
                    try
                    {
                        Console.WriteLine("Please Type side lenght 1 for the RightAngle Triangle");
                        int riside1 = int.Parse(Console.ReadLine());

                        Console.WriteLine("Please Type side lenght 2 for the RightAngle Triangle");
                        int riside2 = int.Parse(Console.ReadLine());

                        if (riside1 < 1)
                        {
                            throw new LessThanOneExecption();
                        }

                        Rightangle ri = new Rightangle(Convert.ToDouble(riside1), Convert.ToDouble(riside2), ricolor);

                        double riside3 = ri.Side3Length;

                        Console.WriteLine("Your created a " + ricolor + " RightAngle Triangle with Sidelength1 : " + riside1 + " and Sidelength2: " + riside2 + " and Sidelength3: " + riside3);
                    }

                    catch (LessThanOneExecption e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Side Length cannot be less than 1");
                    }

                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Integer only for Side Length");
                    }
                }

                else if (inputshape == "E")
                {
                    Console.WriteLine("You Selected Circle, Please Type color for the shape");
                    string cicolor = Console.ReadLine();
                    try
                    {
                        Console.WriteLine("Please Type side lenght for the Circle");
                        int radios = int.Parse(Console.ReadLine());

                        if (radios < 1)
                        {
                            throw new LessThanOneExecption();
                        }

                        Circle sq = new Circle(Convert.ToDouble(radios), cicolor);

                        Console.WriteLine("Your created a " + cicolor + " Circle with Radios: " + radios);
                    }

                    catch (LessThanOneExecption e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Side Length cannot be less than 1");
                    }

                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Integer only for Side Length");
                    }
                }

                else
                {
                    throw new InvaildInputException();
                }
            }

            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("This Generater only accept Letter to create shape ");
            }

            catch (InvaildInputException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("You Have to Type [A] ro [B] or [C] or [D] or [E] to create shape");
            }
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            bool running = true;

            while (running)
            {
                Console.Clear();

                Console.WriteLine("Make a Shape!");
                Console.WriteLine("1. Square");
                Console.WriteLine("2. Rectangle");
                Console.WriteLine("3. Equilateral Triangle");
                Console.WriteLine("4. Right Angle Triangle");
                Console.WriteLine("5. Circle");
                Console.WriteLine("e. Exit");

                switch (Console.ReadLine())
                {
                case "1":
                {
                    Console.Clear();
                    Console.WriteLine("You are making a square");
                    Console.WriteLine("What colour is it?");
                    string colour = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} square");
                    Console.WriteLine("What is its side length?");
                    double side   = GetNum();
                    Square square = new Square(side);
                    square.Colour = colour;
                    Console.Clear();
                    Console.WriteLine($"You created a {colour} square with side length: {side}, an area of {square.GetArea()} and a perimeter of {square.GetPerimeter()}");
                    Console.ReadKey();
                }
                break;

                case "2":
                {
                    Console.Clear();
                    Console.WriteLine("You are making a rectangle");
                    Console.WriteLine("What colour is it?");
                    string colour = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} rectangle");
                    Console.WriteLine("How wide is it?");
                    double width = GetNum();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} rectangle with width: {width}");
                    Console.WriteLine("How tall is it?");
                    double    height    = GetNum();
                    Rectangle rectangle = new Rectangle(width, height);
                    rectangle.Colour = colour;
                    Console.Clear();
                    Console.WriteLine($"You created a {colour} rectangle with width: {width}, height: {height}, an area of {rectangle.GetArea()} and a perimeter of {rectangle.GetPerimeter()}");
                    Console.ReadKey();
                }
                break;

                case "3":
                {
                    Console.Clear();
                    Console.WriteLine("You are making an equilateral triangle");
                    Console.WriteLine("What colour is it?");
                    string colour = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} equilateral triangle");
                    Console.WriteLine("What is its side length?");
                    double      side = GetNum();
                    Equilateral equilateralTriangle = new Equilateral(side);
                    equilateralTriangle.Colour = colour;
                    Console.Clear();
                    Console.WriteLine($"You created a {colour} equilateral triangle with side length: {side}, an area of {equilateralTriangle.GetArea()} and a perimeter of {equilateralTriangle.GetPerimeter()}");
                    Console.ReadKey();
                }
                break;

                case "4":
                {
                    Console.Clear();
                    Console.WriteLine("You are making a right angle triangle");
                    Console.WriteLine("What colour is it?");
                    string colour = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} right angle triangle");
                    Console.WriteLine("How wide is it?");
                    double width = GetNum();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} right angle triangle with base: {width}");
                    Console.WriteLine("How tall is it?");
                    double     height             = GetNum();
                    RightAngle rightAngleTriangle = new RightAngle(width, height);
                    rightAngleTriangle.Colour = colour;
                    rightAngleTriangle.SetHypotenuse();
                    Console.Clear();
                    Console.WriteLine($"You created a {colour} right angle triangle with base: {width}, height: {height}, hypotenuse: {rightAngleTriangle.Side3Length}, an area of {rightAngleTriangle.GetArea()} and a perimeter of {rightAngleTriangle.GetPerimeter()}");
                    Console.ReadKey();
                }
                break;

                case "5":
                {
                    Console.Clear();
                    Console.WriteLine("You are making a circle");
                    Console.WriteLine("What colour is it?");
                    string colour = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} circle");
                    Console.WriteLine("What is its radius?");
                    double radius = GetNum();
                    Circle circle = new Circle();
                    circle.Radius = radius;
                    circle.Colour = colour;
                    Console.Clear();
                    Console.WriteLine($"You created a {colour} circle with radius: {radius}, an area of {circle.GetArea()} and a perimeter of {circle.GetPerimeter()}");
                    Console.ReadKey();
                }
                break;

                case "e":
                {
                    running = false;
                }
                break;

                default:
                    continue;
                }
            }
        }
Beispiel #18
0
        public static int DenormalizeYear(double[] year)
        {
            var eq = new Equilateral(2011, -1, 1);

            return(eq.Decode(year));
        }
Beispiel #19
0
        public double[] NormalizeMonth(int month)
        {
            var eq = new Equilateral(12, -1, 1);

            return(eq.Encode(month));
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            WL("1 - Quadrilateral");
            WL("2 - Triangle");
            WL("3 - Circle");
            space();

            ConsoleKeyInfo Menu1;

            Menu1 = Console.ReadKey();
            ////////////////// Quadrilateral //////////////////
            if (Menu1.Key == ConsoleKey.D1)
            {
                space();
                WL("Input Color");
                space();
                string UColor = Console.ReadLine();
                space();
                WL("1 - Square");
                WL("2 - Rectangle");
                space();
                ConsoleKeyInfo Menu2;
                Menu2 = Console.ReadKey();
                ////////////////// Square //////////////////
                if (Menu2.Key == ConsoleKey.D1)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Square newSq = new Square(UColor, Uside1);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newSq.GetArea(Uside1));
                        WL("Perimeter: " + newSq.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                ////////////////// Rectangle //////////////////
                if (Menu2.Key == ConsoleKey.D2)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        WL("Input side length 2");
                        double Uside2    = double.Parse(Console.ReadLine());
                        string Uside2Str = Uside2.ToString();
                        space();
                        if (Uside2 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside2Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Rectangle newRec = new Rectangle(UColor, Uside1, Uside2);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newRec.GetArea(Uside1));
                        WL("Perimeter: " + newRec.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                Console.ReadKey();
            }
            ////////////////// Triangle //////////////////
            if (Menu1.Key == ConsoleKey.D2)
            {
                space();
                WL("Input Color");
                space();
                string UColor = Console.ReadLine();
                space();
                WL("1 - Equilateral");
                WL("2 - Right-Angled");
                space();
                ConsoleKeyInfo Menu2;
                Menu2 = Console.ReadKey();
                //////////////////  Equilateral //////////////////
                if (Menu2.Key == ConsoleKey.D1)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Equilateral newEq = new Equilateral(UColor, Uside1);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newEq.GetArea(Uside1));
                        WL("Perimeter: " + newEq.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                ////////////////// Right-Angled //////////////////
                if (Menu2.Key == ConsoleKey.D2)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        WL("Input side length 2");
                        double Uside2    = double.Parse(Console.ReadLine());
                        string Uside2Str = Uside2.ToString();
                        space();
                        if (Uside2 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside2Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        RightAngled newRA = new RightAngled(UColor, Uside1, Uside2);
                        newRA.SetHypotenuse(Uside1, Uside2);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newRA.GetArea(Uside1));
                        WL("Perimeter: " + newRA.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                Console.ReadKey();
            }
            ////////////////// Circle //////////////////
            if (Menu1.Key == ConsoleKey.D3)
            {
                try
                {
                    space();
                    WL("Input Color");
                    space();
                    string UColor = Console.ReadLine();
                    space();
                    WL("Input radius");
                    double URad    = double.Parse(Console.ReadLine());
                    string URadStr = URad.ToString();
                    int    d;
                    if (URad < 1)
                    {
                        throw (new InvalidIntException(""));
                    }
                    if (!int.TryParse(URadStr, out d))
                    {
                        throw (new InvalidDecException(""));
                    }
                    space();
                    Circle newCirc = new Circle(UColor, URad);
                    space();
                    WL("Color: " + UColor);
                    WL("Area: " + newCirc.GetArea(URad));
                    WL("Circumference: " + newCirc.GetPerimeter(URad));
                }
                catch (InvalidIntException e)
                {
                    space();
                    WL(e.Message);
                }
                catch (InvalidDecException e)
                {
                    space();
                    WL(e.Message);
                }
                finally
                {
                    WL("Thanks for using the app!");
                }
            }
            Console.ReadKey();
        }
Beispiel #21
0
        public double[] NormalizeSeconds(int Seconds)
        {
            var eq = new Equilateral(60, -1, 1);

            return(eq.Encode(Seconds));
        }
Beispiel #22
0
        public int DenormalizeSeconds(double[] seconds)
        {
            var eq = new Equilateral(60, -1, 1);

            return(eq.Decode(seconds));
        }
Beispiel #23
0
        public double[] NormalizeHour(int hour)
        {
            var eq = new Equilateral(24, -1, 1);

            return(eq.Encode(hour));
        }
Beispiel #24
0
        public int DenormalizeHour(double[] hour)
        {
            var eq = new Equilateral(24, -1, 1);

            return(eq.Decode(hour));
        }
Beispiel #25
0
        public int DenormalizeDays(double[] days)
        {
            var eq = new Equilateral(31, -1, 1);

            return(eq.Decode(days));
        }
Beispiel #26
0
        public double[] NormalizeDays(int days)
        {
            var eq = new Equilateral(31, -1, 1);

            return(eq.Encode(days));
        }
Beispiel #27
0
        public double[] NormalizeYear(int hour, int MaxYear)
        {
            var eq = new Equilateral(MaxYear, -1, 1);

            return(eq.Encode(hour));
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("1. Create Square");
                Console.WriteLine("2. Create Rectangle");
                Console.WriteLine("3. Create Equilateral Triangle");
                Console.WriteLine("4. Create Right Angle Triangle");
                Console.WriteLine("5. Create Circle");
                Console.WriteLine("6. Exit");

                Console.Write("Choose an option: ");

                var choiceText = Console.ReadLine();

                int choice;
                try {
                    choice = int.Parse(choiceText);
                } catch (FormatException) {
                    Console.WriteLine("Please enter a number");

                    continue;
                }

                switch (choice)
                {
                case 1: {
                    Console.Write("Enter colour: ");
                    var colour = Console.ReadLine();

                    var sideLength1 = RetrieveLength("size");

                    var square = new Square(sideLength1);
                    square.Colour = colour;

                    Console.WriteLine("Successfully created a Square");
                } break;

                case 2: {
                    Console.Write("Enter colour: ");
                    var colour = Console.ReadLine();

                    var sideLength1 = RetrieveLength("first side length");
                    var sideLength2 = RetrieveLength("second side length");

                    var rectangle = new Rectangle(sideLength1, sideLength2);
                    rectangle.Colour = colour;

                    Console.WriteLine("Successfully created a Rectangle");
                } break;

                case 3: {
                    Console.Write("Enter colour: ");
                    var colour = Console.ReadLine();

                    var sideLength1 = RetrieveLength("side length");

                    var equilateral = new Equilateral(sideLength1);
                    equilateral.Colour = colour;

                    Console.WriteLine("Successfully created an Equilateral Triangle");
                } break;

                case 4: {
                    Console.Write("Enter colour: ");
                    var colour = Console.ReadLine();

                    var sideLength1 = RetrieveLength("first side length");
                    var sideLength2 = RetrieveLength("second side length");

                    var rightAngle = new RightAngle(sideLength1, sideLength2);
                    rightAngle.Colour = colour;

                    Console.WriteLine("Successfully created a Right Angle Triangle");
                } break;

                case 5: {
                    Console.Write("Enter colour: ");
                    var colour = Console.ReadLine();

                    var radius = RetrieveLength("radius");

                    var circle = new Circle();
                    circle.Radius = radius;
                    circle.Colour = colour;

                    Console.WriteLine("Successfully created a Circle");
                } break;

                case 6: {
                    return;
                } break;

                default: {
                    Console.WriteLine($"Option {choice} not found");
                } break;
                }
            }
        }
Beispiel #29
0
        public double[] NormalizeYear(int year)
        {
            var eq = new Equilateral(2011, -1, 1);

            return(eq.Encode(year));
        }
Beispiel #30
0
        public int DenormalizeMonth(double[] montharry)
        {
            var eq = new Equilateral(12, -1, 1);

            return(eq.Decode(montharry));
        }
Beispiel #31
0
        public int DenormalizeYear(double[] days, int MaxYear)
        {
            var eq = new Equilateral(MaxYear, -1, 1);

            return(eq.Decode(days));
        }