public void Test_CalculateSpeed() { Assert.Multiple(() => { Assert.That(service.CalculateSpeed(1.5f, 44), Is.EqualTo(29.333334f).Within(0.05f)); Assert.That(service.CalculateSpeed(4f, 7), Is.EqualTo(1.75f).Within(0.05f)); Assert.That(service.CalculateSpeed(23f, 45), Is.EqualTo(1.95652175f).Within(0.05f)); Assert.That(service.CalculateSpeed(22f, 280), Is.EqualTo(12.727273f).Within(0.05f)); }); }
static void menySpeed() { ConverterService converter = new ConverterService(); float time = 0, distans = 0; Console.WriteLine("skriv in distans i meter"); while (!float.TryParse(Console.ReadLine(), out distans)) { Console.WriteLine("Värdet kan inte hanteras försök igen"); } Console.WriteLine("skriv in tid"); while (!float.TryParse(Console.ReadLine(), out time)) { Console.WriteLine("Värdet kan inte hanteras försök igen"); } float inputSpeed = converter.CalculateSpeed(time, distans); Console.WriteLine("Resultat är följande, du har färdats i {0} mps", inputSpeed); }
static void CalculateSpeed(ConverterService converter) { //lil johan Console.WriteLine("You have chosen to Calculate the Speed!"); Console.WriteLine("To Calculate the Speed, you'll need to enter some stuff!"); Console.WriteLine("Input Time:"); bool timechecker = Single.TryParse(Console.ReadLine(), out float time); //tryparse time Console.WriteLine("Input Distance:"); bool distancechecker = Single.TryParse(Console.ReadLine(), out float distance); //tryparse distance if (timechecker == false || distancechecker == false) //if checks on timecheck and distancecheck failed do this { Console.WriteLine("you done goofed"); } else //if checks didnt fail do this { float timeResults = converter.CalculateSpeed(time, distance); // Console.WriteLine("You have inputed the time {0}, and the distance {1}.", time, distance); Console.WriteLine("It has resulted in the Speed of {0}!", timeResults); } }
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"); } } }
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"); } } }
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; } } }