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());