public static bool IsNumericDigit(char c) {
return '0' <= c && c <= '9';
public static bool HasNumericDigits(string s) {
for (int i = 0; i < s.Length; i++) {
if (IsNumericDigit(s[i])) return true;
public static bool IsValidPhoneNumber(string s, out string strPhoneNumber) {
for (int i=0; i < s.Length; i++) {
if (IsNumericDigit(s[i]))
return strPhoneNumber.Length == 10;
public static bool IsValidEmail(string s) {
if (word.Length != 2 || word[0].Length == 0)
word = domain.Split('.');
if (word.Length != 2 || word[0].Length == 0)
public static void Main (string[] args)
const short Capacity = 40;
const byte NameColumn = 30;
const byte PhoneColumn = 15;
const byte EmailColumn = 30;
const byte GPAColumn = 4;
const byte Seperator2Length = NameColumn + PhoneColumn + EmailColumn + GPAColumn;
"Name".PadRight(NameColumn) +
"Phone".PadRight(PhoneColumn) +
"Email".PadRight(EmailColumn) +
"GPA".PadRight(GPAColumn);
" ".PadLeft(NameColumn, '=') +
" ".PadLeft(PhoneColumn, '=') +
" ".PadLeft(EmailColumn, '=') +
"".PadLeft(GPAColumn, '=');
string Seperator2 = "".PadLeft(Seperator2Length, '=');
string[] FullNameArray = new string[Capacity];
string[] PhoneNumberArray = new string[Capacity];
string[] FinalNumberArray = new string[Capacity];
string[] EmailArray = new string[Capacity];
string[] GPAArray = new string[Capacity];
double[] DoubleGPAArray = new double[Capacity];
string StudentEmail = "";
bool ValidLastName = true;
bool ValidFirstName = true;
bool ValidMiddleName = true;
bool ValidPhoneNumber = true;
Console.WriteLine("Last name =");
LastName = Console.ReadLine();
ValidLastName = (Validate.HasNumericDigits(LastName) == false);
} while (!ValidLastName);
if (LastName == "") continue;
Console.WriteLine("First name =");
FirstName = Console.ReadLine();
ValidFirstName = (FirstName != "" && (Validate.HasNumericDigits(FirstName) == false));
} while (!ValidFirstName);
Console.WriteLine("Middle name =");
MiddleName = Console.ReadLine();
ValidMiddleName = (Validate.HasNumericDigits(MiddleName) == false);
} while (!ValidMiddleName);
Console.WriteLine("Phone =");
number = Console.ReadLine();
ValidPhoneNumber = number == "" || Validate.IsValidPhoneNumber(number, out PhoneNumber);
} while (!ValidPhoneNumber);
Console.WriteLine("Email =");
StudentEmail = Console.ReadLine();
ValidEmail = (StudentEmail =="") || Validate.IsValidEmail(StudentEmail);
Console.WriteLine("GPA =");
StudentGPA=Console.ReadLine();
isDouble = Double.TryParse(StudentGPA, out GPA);
ValidGPA = isDouble && (GPA >= 0 && GPA <= 4);
strGPA = Convert.ToString(StudentGPA);
FullNameArray[i] = LastName + ", " + FirstName + " " + MiddleName;
FinalNumberArray[i] = "";
FinalNumberArray[i] = "(" + PhoneNumber.Substring(0,3) + ") " + PhoneNumber.Substring(3,3) + "-" + PhoneNumber.Substring(6,4);
EmailArray[i] = StudentEmail;
} while (i < Capacity && LastName != "");
Console.WriteLine(Header);
Console.WriteLine(Seperator);
for (int j=0; j < i; j++)
Console.WriteLine(FullNameArray[j].PadRight(NameColumn) +
FinalNumberArray[j].PadRight(PhoneColumn) +
EmailArray[j].PadRight(EmailColumn) +
GPAArray[j].PadRight(GPAColumn));
Console.WriteLine(Seperator2);
for (int j = 0; j < i; j++)
GPASum += DoubleGPAArray[j];
GPAAverage = Math.Round((GPASum / i), 2);
Console.WriteLine("There are {0} student(s) with an average GPA of {1}", i, GPAAverage);