diff --git a/Src/BootCamp.Chapter/Checks.cs b/Src/BootCamp.Chapter/Checks.cs index 49864932a..4ce0cf783 100644 --- a/Src/BootCamp.Chapter/Checks.cs +++ b/Src/BootCamp.Chapter/Checks.cs @@ -17,25 +17,29 @@ public static class Checks public static int PromptInt(string message) { // To do: call your implementation. - return 0; + var i = Lesson4.getThenConvertInt(message); + return i; } public static string PromptString(string message) { // To do: call your implementation. - return ""; + var i = Lesson4.getString(message); + return i; } public static float PromptFloat(string message) { // To do: call your implementation. - return 0; + var i = Lesson4.getStringConvertFloat(message); + return i; } public static float CalculateBmi(float weight, float height) { // To do: call your implementation. - return 0; + var i = Lesson4.calcBMI(weight, height); + return i; } } } diff --git a/Src/BootCamp.Chapter/Lesson4.cs b/Src/BootCamp.Chapter/Lesson4.cs new file mode 100644 index 000000000..e919ad453 --- /dev/null +++ b/Src/BootCamp.Chapter/Lesson4.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; + +namespace BootCamp.Chapter +{ + internal class Lesson4 + { + public static int getThenConvertInt(string message) + { + Console.WriteLine(message); + var input = Console.ReadLine(); + int n; + bool isNumber = int.TryParse(input, out _); + if (!isNumber) + { + Console.WriteLine("\"" + input + "\"" + " is not a valid number."); + return -1; + } + + return int.Parse(input); + } + + public static string getString(string message) + { + Console.WriteLine(message); + var input = Console.ReadLine(); + if (String.IsNullOrEmpty(input)) + { + Console.WriteLine($"{message} Name cannot be empty {input}"); + return "-"; + } + return input; + + } + + public static float getStringConvertFloat(string message) + { + Console.WriteLine(message); + var input = Console.ReadLine(); + bool isNumber = float.TryParse(input, out _); + if (isNumber) { + return float.Parse(input); + } + else + { + Console.WriteLine("\"" + input + "\"" + " is not a valid number."); + return -1; + + } + } + + public static float calcBMI(float weight, float height) + { + + if (weight <= 0 || height <= 0) + { + var reasons = "Failed calculating BMI. Reason:"; + if (weight <= 0) reasons += $"/nWeight cannot be equal or less than zero, but was {weight} "; + if (height <= 0) reasons += $"/nHeight cannot be equal or less than zero, but was {height}" ; + Console.WriteLine(reasons); + return -1; + } + float BMI = ((float)(weight / (Math.Pow(height, 2)))); + return BMI; + } + } + } + diff --git a/Src/BootCamp.Chapter/Program.cs b/Src/BootCamp.Chapter/Program.cs index 94e5531bc..5581e8846 100644 --- a/Src/BootCamp.Chapter/Program.cs +++ b/Src/BootCamp.Chapter/Program.cs @@ -9,6 +9,41 @@ class Program { static void Main(string[] args) { + var weight = Lesson4.getThenConvertInt("Enter Weight"); + var height = Lesson4.getThenConvertInt("Enter Height"); + var name = Lesson4.getString("Enter Name"); + + var BMI = Lesson4.calcBMI(weight, height); + + + + //Console.WriteLine("Please enter an First Name: "); + //var firstName = Console.ReadLine(); + //Console.WriteLine($"Please enter {firstName}'s Last Name: "); + //var lastName = Console.ReadLine(); + //var fullName = firstName + " " + lastName; + //Console.WriteLine($"Please enter {fullName}'s age: "); + //var age = Console.ReadLine(); + //Console.WriteLine($"Please enter {fullName}'s Weight (kg): "); + //double weight = Convert.ToDouble(Console.ReadLine()); + //Console.WriteLine($"Please enter {fullName}'s Height (cm): "); + //double height = Convert.ToDouble(Console.ReadLine()); + Console.WriteLine($"{name}'s ,weight is {weight} height is {height} cm BMI is {BMI}"); + + //Console.WriteLine($"{fullName}'s BMI is {BMI.GetBMI((height / 100), weight)}"); + } + + + + // BMIformula = weight (lb) / [height (in)]2 x 703 + public class BMI + { + public static double GetBMI(double height, double weight) + { + return (weight / (Math.Pow(height, 2))); + } } + + } -} +} \ No newline at end of file diff --git a/Src/Lesson3.cs b/Src/Lesson3.cs new file mode 100644 index 000000000..285d204ac --- /dev/null +++ b/Src/Lesson3.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BootCamp.Chapter +{ + internal class Lesson3 + { + public static int getThenConvertInt(string message) + { + Console.WriteLine(message); + var input = Console.ReadLine(); + return int.Parse(input); + } + + public static string getString(string message) + { + Console.WriteLine(message); + var input = Console.ReadLine(); + return input; + + } + + public static float getStringConvertFloat(string message) + { + Console.WriteLine(message); + var input = Console.ReadLine(); + return float.Parse(input); + } + + public static float calcBMI(float weight, float height) + { + float BMI = ((float)(weight / (Math.Pow(height, 2)))); + return BMI; + } + } + } +