From 7110a702b733c6f8752916cf9fa0837e2777af90 Mon Sep 17 00:00:00 2001 From: LostCSharp7 Date: Thu, 28 Sep 2023 10:03:52 +0530 Subject: [PATCH] Pull request for Homework. --- Src/BootCamp.Chapter/BootCamp.Chapter.csproj | 2 +- Src/BootCamp.Chapter/Checks.cs | 17 ++--- Src/BootCamp.Chapter/Lesson3.cs | 71 +++++++++++++++++++ Src/BootCamp.Chapter/Program.cs | 1 + .../BootCamp.Chapter.Tests.csproj | 2 +- 5 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 Src/BootCamp.Chapter/Lesson3.cs diff --git a/Src/BootCamp.Chapter/BootCamp.Chapter.csproj b/Src/BootCamp.Chapter/BootCamp.Chapter.csproj index 958d2f1da..fa2362844 100644 --- a/Src/BootCamp.Chapter/BootCamp.Chapter.csproj +++ b/Src/BootCamp.Chapter/BootCamp.Chapter.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + netcoreapp6.0 diff --git a/Src/BootCamp.Chapter/Checks.cs b/Src/BootCamp.Chapter/Checks.cs index 49864932a..b574c0ce0 100644 --- a/Src/BootCamp.Chapter/Checks.cs +++ b/Src/BootCamp.Chapter/Checks.cs @@ -16,26 +16,27 @@ public static class Checks { public static int PromptInt(string message) { - // To do: call your implementation. - return 0; + // To do: call your implementation. + return Lesson3.PromptInt(message); } public static string PromptString(string message) { - // To do: call your implementation. - return ""; + // To do: call your implementation. + return Lesson3.PromptString(message); + } public static float PromptFloat(string message) { - // To do: call your implementation. - return 0; + return Lesson3.PromptFloat(message); + } public static float CalculateBmi(float weight, float height) { - // To do: call your implementation. - return 0; + return Lesson3.CalculateBMI(weight, height); + } } } diff --git a/Src/BootCamp.Chapter/Lesson3.cs b/Src/BootCamp.Chapter/Lesson3.cs new file mode 100644 index 000000000..bac527d0e --- /dev/null +++ b/Src/BootCamp.Chapter/Lesson3.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.Globalization; +using System.Text; + +namespace BootCamp.Chapter +{ + internal class Lesson3 + { + public static void demo() + { + + string name = PromptString("Enter your name: "); + string surName = PromptString("Enter your surname: "); + int age = PromptInt("Enter your age: "); + float height = PromptFloat("Enter your height(m): "); + float weight = PromptFloat("Enter your waight(Kg): "); + + Console.WriteLine(name + " " + surName + " is " + age + " years old, his weight is " + weight + " kg and his height is " + height + "m."); + double bodyMassIndex = CalculateBMI(weight, height); + Console.WriteLine("Body Mass Index measured for " + name + " " + surName + " is " + bodyMassIndex); + + + } + + public static float CalculateBMI(float weight, float height) + { + float bodyMassIndex = (weight / (height * height)); + return bodyMassIndex; + } + + public static int PromptInt(string Message) + { + int age; + do + { + Console.Write(Message); + if (int.TryParse(Console.ReadLine(), out age)) + break; + else + Console.Write("Please enter number for age, "); + } while (true); + + return age; + + } + + public static float PromptFloat(string Message) + { + float metrics; + do + { + Console.Write(Message); + if (float.TryParse(Console.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo , out metrics)) + break; + else + Console.Write("Please enter number\\decimal,"); + } while (true); + return metrics; + } + + public static string PromptString(string Message) + { + string Name; + Console.Write(Message); + Name = Console.ReadLine(); + return Name; + } + } +} diff --git a/Src/BootCamp.Chapter/Program.cs b/Src/BootCamp.Chapter/Program.cs index 94e5531bc..729a1ef0c 100644 --- a/Src/BootCamp.Chapter/Program.cs +++ b/Src/BootCamp.Chapter/Program.cs @@ -9,6 +9,7 @@ class Program { static void Main(string[] args) { + Lesson3.demo(); } } } diff --git a/Tests/BootCamp.Chapter.Tests/BootCamp.Chapter.Tests.csproj b/Tests/BootCamp.Chapter.Tests/BootCamp.Chapter.Tests.csproj index 3a8778c77..ffca4abc4 100644 --- a/Tests/BootCamp.Chapter.Tests/BootCamp.Chapter.Tests.csproj +++ b/Tests/BootCamp.Chapter.Tests/BootCamp.Chapter.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.0 + netcoreapp6.0 false