public void Test_CalculateTravelTime()
 {
     Assert.Multiple(() =>
     {
         Assert.That(service.CalculateTravelTime(80, 120), Is.EqualTo(1.5).Within(0.005f));
         Assert.That(service.CalculateTravelTime(120, 0), Is.EqualTo(0).Within(0.005f));
         Assert.That(service.CalculateTravelTime(55, 230), Is.EqualTo(4.181818).Within(0.005f));
     });
 }
        static void menyTravelTime()
        {
            ConverterService converter = new ConverterService();

            float speed = 0, distance = 0;

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

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

            Console.WriteLine("Resultat är följande, du har färdats i {0} sekunder", inputTime);
        }
        static void CalculateTravelTime(ConverterService converter)
        { //lil johan
            Console.WriteLine("You have chosen to Calculate the TravelTime!");
            Console.WriteLine("To Calculate the Traveltime, 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 Distance:");
            bool distancechecker = Single.TryParse(Console.ReadLine(), out float distance); //tryparse distance

            if (speedchecker == false || distancechecker == false)                          //if checks on speedcheck and distancecheck failed do this
            {
                Console.WriteLine("you done goofed");
            }
            else     //if checks didnt fail do this
            {
                float timeResults = converter.CalculateTravelTime(speed, distance);
                //
                Console.WriteLine("You have inputed the speed{0}, and the distance{1}.", speed, distance);
                Console.WriteLine("It has resulted in the TravelTime of {0}!", timeResults);
            }
        }
示例#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");
                }
            }
        }
示例#5
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;
                }
            }
        }