Hi Guys
NP84 Calculating Stock Options
In the program Number of stock options for Manager 9000. To calculate this a code is given. I couldn’t understand this code. Anyone knows please explain.
numberOfOptions += (ulong)r.Next(500);
Thank you
using System;
namespace Employees
{
// Employee is the base class in this hierarchy. It serves to hold data & functionality
// common to all employee types.
abstract public class Employee
{
// protected data for kids.
protected string fullName;
protected int empID;
protected float currPay;
protected string empSSN;
#region Constructors
public Employee() { } // Default ctor.
public Employee(string FullName, int empID, float currPay, string ssn) // Custom ctor
{
// Assign internal state data. Note use of 'this' keyword to avoid name clashes.
this.fullName = FullName;
this.empID = empID;
this.currPay = currPay;
this.empSSN = ssn;
}
#endregion
#region Methods
public virtual void GiveBonus(float amount) // Bump the pay for this emp.
{ currPay += amount; }
// Show state (could use ToString() as well)
public virtual void DisplayStats()
{
Console.WriteLine("Name: {0}", fullName);
Console.WriteLine("Pay: {0}", currPay);
Console.WriteLine("ID: {0}", empID);
Console.WriteLine("SSN: {0}", empSSN);
}
#endregion
}
public class Manager : Employee
{
private ulong numberOfOptions;
#region Constructors
public Manager(string FullName, int empID, float currPay, string ssn, ulong numbOfOpts)
: base(FullName, empID, currPay, ssn)
{
// This point of data belongs with us!
numberOfOptions = numbOfOpts;
}
#endregion
#region Methods and properties
public override void GiveBonus(float amount)
{
// Increase salary.
base.GiveBonus(amount);
// And give some new stock options...
Random r = new Random();
numberOfOptions += (ulong)r.Next(500);
}
public override void DisplayStats()
{
base.DisplayStats();
Console.WriteLine("Number of stock options: {0}", numberOfOptions);
}
#endregion
}
public class EmpApp
{
public static int Main(string[] args)
{
Manager chucky = new Manager("Chucky", 92, 100000, "333-23-2322", 9000);
chucky.GiveBonus(300);
chucky.DisplayStats();
return 0;
}
}
}
/*
Name: Chucky
Pay: 100300
ID: 92
SSN: 333-23-2322
Number of stock options: 9492
*/