I have 3 Subclasses " Staff, Faculty, Student" each class is getting the users first initial lastname from the parent class person, to this id like to add 4 random numbers when the console application is run. The problem I am having is that all of the classes are getting the same 4 digits how can I fix this and yes it has to be done using Random I cant use static counters.
Person.cs "Parent Class"
public class Person
{
static string title;
protected string firstName;
protected string lastName;
protected string address;
protected string gender;
protected string dateOfBirth;
protected string userID;
protected Random rnd = new Random();
Faculty.cs
namespace Person
{
public class Faculty : Person
{
public Faculty(string aTitle, string aFirstName, string aLastName, string aAddress,
string aGender, string aDateOfBirth)
: base(aTitle, aFirstName, aLastName, aAddress,
aGender, aDateOfBirth)
{
this.userID = firstName.Substring(0, 1) + lastName.Substring(0, 5);
this.userID = this.userID + rnd.Next(1000, 9999);
Console.WriteLine(this.userID);
}
}
}
Staff.cs
namespace Person
{
public class Staff : Person
{
public Staff(string aTitle, string aFirstName, string aLastName, string aAddress,
string aGender, string aDateOfBirth)
: base(aTitle, aFirstName, aLastName, aAddress,
aGender, aDateOfBirth)
{
this.userID = firstName.Substring(0, 1) + lastName.Substring(0, 5);
this.userID = this.userID + rnd.Next(1000, 9999);
Console.WriteLine(userID);
}
}
}
Test Class
public class PersonTest
{
static void Main(string[] args)
{
Person testPerson = new Faculty(" Mr.", "Merry ", "Lanes", " 493 Bluebane RD", "Male", " 8-06-1953\n ");
Person studentPerson = new Student(" Mr.", "Jerry ", "Panes", " 456 Greenbane RD", "Male", " 8-10-1945\n");
Person staffPerson = new Staff(" Mr.", "Joe ", "Gaines", " 495 Redbane RD", "Male", " 8-21-1989\n ");
Console.ReadLine();
}//end main