I have to create two classes. the base class is Employee
and it needs 2 protected fields. A string Name
and an int Number
. I then have to create a derived class called ProductionWorker
with 4 properties. the first two are the 2 inherited properties from the base class. the next two are double PayRate
and int ShiftNum
. The user enters this data on a form. Once the show button is clicked these 4 data points need to be intialized into the ProductionWorker object as properties. Then using the object I must show this data as a string.
I've read about : base after the derived class's constructor. But I still can't initialize the ProductionWorker because it doesn't take the entire 4 parameters?
namespace Employee_Form
{
class Employee
{
protected string Name { get; set; }
protected int Number { get; set; }
public Employee(string name, int number)
{
this.Name = name;
this.Number = number;
}
}
}
namespace Employee_Form { class ProductionWorker : Employee { protected static new string Name { get; set; } protected static new int Number { get; set; } protected int ShiftNum { get; set; } protected double PayRate { get; set; }
public ProductionWorker(int shiftNum, double payRate) : base (Name, Number)
{
this.ShiftNum = shiftNum;
this.PayRate = payRate;
}
public string showData()
{
}
}
}
namespace Employee_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
ProductionWorker worker = new ProductionWorker(Convert.ToInt32(textBox3.Text),
Convert.ToDouble(textBox4.Text),
textBox1.Text,
textBox2.Text);
}
}
}