Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 970915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:52:42+00:00 2026-05-16T02:52:42+00:00

What I am trying to do is get the UserID to generate random values

  • 0

What I am trying to do is get the UserID to generate random values based on the type of class it is the userID should be generated from person.cs.
For example the student class generates a student id and a random number the staff class is supposed to generate a staff id and a random number, the issue I am having is getting any userID sample data to show up at all in the console output, I don’t get any data to show up for the userID can anyone help me.

Here’s the links requested to view the code

Person.cs

PersonTest.cs

Student.cs

Staff.cs

Faculty.cs

Person.cs

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();
    // constructors
    public Person()
    {

    }//end default constructor

    public Person(string aTitle, string aFirstName, string aLastName, string aAddress,
        string aGender, string aDateOfBirth)
    {
        title = aTitle;
        firstName = aFirstName;
        lastName = aLastName;
        address = aAddress;
        gender = aGender;
        dateOfBirth = aDateOfBirth;
        Console.WriteLine( this.DisplayInfo() );

        //create userID


        Console.WriteLine(userID);

        this.DisplayInfo();
    }//end 6-parameter constructor

Just Added

public string DisplayInfo()
    {
        return " You have created the person " + firstName + lastName +"\n whose address is" + address + "\n" + " whos is a " + gender + " and was born on " + dateOfBirth;
    }//end method DisplayInfo

Staff.cs student.cs has the same data for now

  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 + this.rnd.Next(1000, 9999);


        }

PersonTest.cs

  public class PersonTest
    {
       static void Main(string[] args) 
      { 
            Person testPerson = new Student("Mr.", "Merry ", "Lanes", " 493 Bluebane RD", "Male", " 8-06-1953 ");


            Person studentPerson = new Person("Mr.", "Jerry ", "Panes", " 493 Bluebane RD", "Male", " 8-06-1953 "); 

            // THIS DATA SHOWS UP BUT NOT THE USERID



            Console.ReadLine();
        }//end main

UML Diagram

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:52:43+00:00Added an answer on May 16, 2026 at 2:52 am

    OK, this turns out to be a question about the sequence of constructors.

    The base-class constructor(s) are always called first. You can somehow see that in the syntax of a derived class, the call to the base ctor happens between the parameter list and the derived body.

    we have:

    public class Person(....)
    {
        protected string userID;
    
        public Person(....)
        {
          //create userID   //no, print it
          Console.WriteLine(userID);
        }
    }
    
    public class Staff : Person
    {
        public Staff(...)
          : base(....)         // now it is printed
        {
           this.userID = ...;  // and now it is filled
        } 
    }
    

    Btw, using a random number for ID is questionable. Use a (static ounter) to generate 0,1,2,3 and you have zero chance of a collision. Regardless of the prefix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Im trying to get a completly data copy from a gridview, itryed clone(), tryed
Trying to get my css / C# functions to look like this: body {
Trying to get an ASP application deployed; it worked for a while but then
Whilst trying to get our app working in Firefox (I'm a big proponent of
Im trying to get into some basic JavaFX game development and I'm getting confused
Just trying to get my head around Generics by reading this enlightening article by
Just trying to get my irb sessions to actually list the current line of
Just trying to get up to speed with the SDK... So, I've created my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.