get; set;

I'm trying to write a simple console app and test app that will generate health information for someone but having difficulty with data validation in my get; set; statement. I need to make sure the date of birth is within a certain date range else return a zero. Any assistance is greatly appreaciated. Code for both apps is below.

P.S. Not trying to re-write the entire thing, just get the validation working.

using System;

public class HealthProfile
{
private string first;
private string last;
private string gender;
private int year;
private int height;
private int weight;
private int age;
private decimal maxTarget;
private decimal minTarget;
private int max;
private int bmi;
private int counter;

//constructor
public HealthProfile()
{
year = -1;
counter = 1;
}//end constructor

public string First { get; set;}
public string Last { get; set; }
public string Gender { get; set; }
public int Year
{
get
{
return year;
}//end get
set
{
if (value >= 1900 && value <= System.DateTime.Today.Year)
year = value;
}//end set
}//end property Year

public int Weight
{
get
{
return weight;
}//end get
set
{
if (value >= 0)
weight = value;
}//end set
}//end property Weight

public int Height
{
get
{
return height;
}//end get
set
{
if (value >= 0)
height = value;
}//end set
}//end property Weight


public void CalcNumbers()
{
//loop
while (counter < 4)
{
Console.WriteLine("Enter your first name:");
first = Console.ReadLine();

Console.WriteLine("Enter your last name:");
last = (Console.ReadLine());

Console.WriteLine("Enter your gender:");
gender = Console.ReadLine();

Console.WriteLine("Enter your year of birth:");
year = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter your weight in pounds:");
weight = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter your height in inches:");
height = Convert.ToInt32(Console.ReadLine());

age = System.DateTime.Today.Year - year;

max = 220 - age;

maxTarget = (max*85/100);

minTarget = max/2;

bmi = (weight * 703) / (height * height);

counter = counter + 1;

Console.WriteLine("Health Profile for {0} {1}:", first, last);
Console.WriteLine("Age: {0}\nBMI: {1}\nMax Heart Rate: {2}\nTarget Heart Rate Range: {3}-{4}\n", age, bmi, max, minTarget, maxTarget);

}//end while
}//end CalcNumbers

//public void DisplayProfile()
//{
// Console.WriteLine("Health Profile for {0} {1}:", first, last);
//Console.WriteLine("Age: {0}\nBMI: {1}\nMax Heart Rate: {2}\nTarget Heart Rate Range: {3}-{4}", age, bmi, max, minTarget, maxTarget);
//}//end method DisplayProfile
}//end class HealthProfile


____________________________________________________
TEST APP
____________________________________________________

using System;

public class HealthProfileTest
{
public static void Main(string[] args)
{
HealthProfile HP = new HealthProfile();

HP.CalcNumbers();
//HP.DisplayProfile();

}//end Main method






}//end class HealthProfileTest
Topic archived. No new replies allowed.