public void Test_CalculateTraveledDistance()
 {
     Assert.Multiple(() => {
         Assert.That(service.CalculateTraveledDistance(100, 1.4f), Is.EqualTo(140.0f).Within(0.05f));
         Assert.That(service.CalculateTraveledDistance(50, 0.5f), Is.EqualTo(25.0f).Within(0.05f));
         Assert.That(service.CalculateTraveledDistance(250, 0.2f), Is.EqualTo(50.0f).Within(0.05f));
         Assert.That(service.CalculateTraveledDistance(70, 1), Is.EqualTo(70.0f).Within(0.05f));
         Assert.That(service.CalculateTraveledDistance(70, 6), Is.EqualTo(420.0f).Within(0.05f));
     });
 }
        static void menyTraveledDistance()
        {
            ConverterService converter = new ConverterService();

            float time = 0, speed = 0;

            Console.WriteLine("skriv in hastighet mps");
            while (!float.TryParse(Console.ReadLine(), out speed))
            {
                Console.WriteLine("Värdet kan inte hanteras försök igen");
            }

            Console.WriteLine("skriv in sekunder som det har tagit");
            while (!float.TryParse(Console.ReadLine(), out time))
            {
                Console.WriteLine("Värdet kan inte hanteras försök igen");
            }
            float inputDistance = converter.CalculateTraveledDistance(time, speed);

            Console.WriteLine("Du har färdats i {0} meter", inputDistance);
        }
Ejemplo n.º 3
0
        static void CalculateTraveledDistance(ConverterService converter)
        { //lil johan
            Console.WriteLine("You have chosen to Calculate the Traveled Distance!");
            Console.WriteLine("To Calculate the Traveled Distance, you'll need to enter some stuff!");
            Console.WriteLine("Input Speed:");
            bool speedchecker = Single.TryParse(Console.ReadLine(), out float speed); //tryparse speed

            Console.WriteLine("Input Time:");
            bool timechecker = Single.TryParse(Console.ReadLine(), out float time); //tryparse time

            if (speedchecker == false || timechecker == false)                      //if checks on speedcheck and timecheck failed do this
            {
                Console.WriteLine("you done goofed");
            }
            else     //if checks didnt fail do this
            {
                float distanceResults = converter.CalculateTraveledDistance(speed, time);
                //
                Console.WriteLine("You have inputed the speed {0}, and the time {1}.", speed, time);
                Console.WriteLine("It has resulted in the TravelTime of {0}!", distanceResults);
            }
        }
Ejemplo n.º 4
0
        static void showTimeDistanceSpeedMenu()
        {
            ConverterService converter = new ConverterService();
            float            distance;
            float            speed;
            float            time;
            int choiceFormat = 0;

            while (choiceFormat != 5)
            {
                Console.WriteLine("\nHuvudmeny/Tid-Distans-Hastighet/");
                Console.WriteLine("\n1. Tid");
                Console.WriteLine("2. Distans");
                Console.WriteLine("3. Hastighet");
                Console.WriteLine("4. Återvänd");
                Console.WriteLine("5. Avsluta");
                Console.WriteLine();

                if (int.TryParse(Console.ReadLine(), out choiceFormat))
                {
                    // Travel Time
                    if (choiceFormat == 1)
                    {
                        Console.WriteLine("Ange kilometer");
                        distance = ifLetterInput();

                        Console.WriteLine("Ange km/h");
                        speed = ifLetterInput();

                        Console.WriteLine("Timmar: {0:0.##}", converter.CalculateTravelTime(speed, distance));
                    }

                    // Travel Distance
                    if (choiceFormat == 2)
                    {
                        Console.WriteLine("Ange timmar");
                        time = ifLetterInput();
                        Console.WriteLine("Ange km/h");
                        speed = ifLetterInput();
                        Console.WriteLine("Kilometer: {0:0.##}", converter.CalculateTraveledDistance(time, speed));
                    }

                    // Travel Speed
                    if (choiceFormat == 3)
                    {
                        Console.WriteLine("Distans");
                        distance = ifLetterInput();
                        Console.WriteLine("Ange timmar");
                        time = ifLetterInput();
                        Console.WriteLine("km/h: {0:0.##}", converter.CalculateSpeed(time, distance));
                    }

                    // Återvänd
                    if (choiceFormat == 4)
                    {
                        break;
                    }

                    // Avsluta
                    if (choiceFormat == 5)
                    {
                        Console.WriteLine("Avslutar...");
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Console.WriteLine("Endast siffror godtas");
                }
            }
        }
Ejemplo n.º 5
0
        static void showAmpResistVoltMenu()
        {
            ConverterService converter = new ConverterService();
            float            amp;
            float            res;
            float            voltage;
            int choiceFormat = 0;

            while (choiceFormat != 4)
            {
                Console.WriteLine("\nHuvudmeny/Amp-Resist-Volt/");
                Console.WriteLine("\n1. Amp");
                Console.WriteLine("2. Resistans");
                Console.WriteLine("3. Voltage");
                Console.WriteLine("4. Återvänd");
                Console.WriteLine("5. Avsluta");
                Console.WriteLine();

                if (int.TryParse(Console.ReadLine(), out choiceFormat))
                {
                    // Calculate Amps
                    if (choiceFormat == 1)
                    {
                        Console.WriteLine("Ange voltage");
                        voltage = ifLetterInput();
                        Console.WriteLine("Ange resistans");
                        res = ifLetterInput();
                        Console.WriteLine("Amps: {0:0.##}", converter.CalculateAmps(voltage, res));
                    }

                    // Calculate Resistance
                    if (choiceFormat == 2)
                    {
                        Console.WriteLine("Ange voltage");
                        voltage = ifLetterInput();
                        Console.WriteLine("Ange amp");
                        amp = ifLetterInput();
                        Console.WriteLine("Resistans: {0:0.##}", converter.CalculateTraveledDistance(voltage, amp));
                    }

                    // Calculate Voltage
                    if (choiceFormat == 3)
                    {
                        Console.WriteLine("Ange amp");
                        amp = ifLetterInput();
                        Console.WriteLine("Ange resistans");
                        res = ifLetterInput();
                        Console.WriteLine("Voltage: {0:0.##}", converter.CalculateSpeed(res, amp));
                    }

                    // Återvänd
                    if (choiceFormat == 4)
                    {
                    }

                    // Avsluta
                    else if (choiceFormat == 5)
                    {
                        Console.WriteLine("Avslutar...");
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Console.WriteLine("Endast siffror godtas, försök igen");
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            string str =
                "Vänligen välj ett alternativ\n" +
                "1. Beräkna Ampere\n" +
                "2.  Beräkna Resistans\n" +
                "3.  Beräkna Diameter\n" +
                "4.  Beräkna Radie\n" +
                "5.  Beräkna Restid\n" +
                "6.  Beräkna Förflyttning\n" +
                "7.  Beräkna Hastighet\n" +
                "8.  Beräkna Spänning\n" +
                "9.  Konvertera Celcius till Fahrenheit\n" +
                "10. Konvertera Fahrenheit till Celcius\n" +
                "11.  Konvertera Gallon till Liter\n" +
                "12.  Konvertera Liter till Gallon\n" +
                "13.  Konvertera Timmar till Minuter\n" +
                "14.  Konvertera Minuter till Timmar\n" +
                "0. Avsluta";

            ConverterService converter = new ConverterService();

            int   val;
            float result;

            while (true)
            {
                Console.WriteLine(str);
                while (!Int32.TryParse(Console.ReadLine(), out val))
                {
                    Console.WriteLine("Felaktigt val {0}\n" + str, val);
                }
                switch (val)
                {
                case 1:
                    result = converter.CalculateAmps(ReadUserData("Ange spänningen"), ReadUserData("Ange resistansen"));
                    Console.WriteLine("Strömmen blir {0} A", result);
                    Console.ReadLine();
                    break;

                case 2:
                    result = converter.CalculateResistance(ReadUserData("Ange Spänningen"), ReadUserData("Ange ampere"));
                    Console.WriteLine("Resistansen blir {0} Ohm", result);
                    Console.ReadLine();
                    break;

                case 3:
                    result = converter.CalculateDiameterFromArea(ReadUserData("Ange area"));
                    Console.WriteLine("Diametern blir {0}", result);
                    Console.ReadLine();
                    break;

                case 4:
                    result = converter.CalculateRadiusFromArea(ReadUserData("Ange area"));
                    Console.WriteLine("Radien blir {0}", result);
                    Console.ReadLine();
                    break;

                case 5:
                    result = converter.CalculateTravelTime(ReadUserData("Ange avståndet"), ReadUserData("Ange Hastigheten"));
                    Console.WriteLine("Resetiden blir {0}", result);
                    Console.ReadLine();
                    break;

                case 6:
                    result = converter.CalculateTraveledDistance(ReadUserData("Ange hastigheten"), ReadUserData("Ange tiden"));
                    Console.WriteLine("Avståndet blir {0}", result);
                    Console.ReadLine();
                    break;

                case 7:
                    result = converter.CalculateSpeed(ReadUserData("Ange tiden"), ReadUserData("Ange avståndet"));
                    Console.WriteLine("Hastigheten blir {0}", result);
                    Console.ReadLine();
                    break;

                case 8:
                    result = converter.CalculateVoltage(ReadUserData("Ange ampere"), ReadUserData("Ange resistans"));
                    Console.WriteLine("Spänningen blir {0} V", result);
                    Console.ReadLine();
                    break;

                case 9:
                    result = converter.ConvertCelciusToFahrenheit(ReadUserData("Ange Celsius"));
                    Console.WriteLine("Angivet värde blir {0} farhenheit", result);
                    Console.ReadLine();
                    break;

                case 10:
                    result = converter.ConvertFahrenheitToCelcius(ReadUserData("Ange Fahrenheit"));
                    Console.WriteLine("Angivet värde blir blir {0} celcius", result);
                    Console.ReadLine();
                    break;

                case 11:
                    result = converter.ConvertFromGallonToLiter(ReadUserData("Ange mängden gallon du vill konvertera till liter"));
                    Console.WriteLine("Angivna gallon är {0} liter", result);
                    Console.ReadLine();
                    break;

                case 12:
                    result = converter.ConvertFromLiterToGallon(ReadUserData("Ange mängden liter du vill konvertera till gallon"));
                    Console.WriteLine("Angivna liter är {0} gallon", result);
                    Console.ReadLine();
                    break;

                case 13:
                    result = converter.ConvertFromHoursToMinutes(ReadUserData("Ange antalet timmar du vill konvertera till minuter"));
                    Console.WriteLine("Angivna timmar blir {0} minuter", result);
                    Console.ReadLine();
                    break;

                case 14:
                    result = converter.ConvertFromMinutesToHours(ReadUserData("Ange antalet minuter du vill konvertera till timmar"));
                    Console.WriteLine("Angivna minuter blir {0} timmar", result);
                    Console.ReadLine();
                    break;

                case 0: return;

                default:
                    Console.WriteLine("Feaktigt val försök igen!");
                    Console.ReadLine();
                    break;
                }
            }
        }