Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework 4 Finished- All Tests Passed #825

Open
wants to merge 1 commit into
base: Chapter1/Homework/4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Src/BootCamp.Chapter/Checks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
70 changes: 70 additions & 0 deletions Src/BootCamp.Chapter/Lesson4.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

37 changes: 36 additions & 1 deletion Src/BootCamp.Chapter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}


}
}
}
38 changes: 38 additions & 0 deletions Src/Lesson3.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}