• Name: The Name property holds the employee’s name.
• idNumber: The idNumber property holds the employee’s ID number.
• Department: The Department property holds the name of the department in which the employee works.
• Position: The Position property holds the employee’s job title.
The class should have the following overloaded constructors:
• A constructor that accepts the following values as arguments and assigns them to the appropriate member properties: employee’s name, employee’s ID number, department, and position.
• A constructor that accepts the following values as arguments and assigns them to the appropriate member properties: employee’s name and ID number. The Department and Position fields should be assigned an empty string (“ “);
• A parameterless constructor that assigns empty strings (“ “) to the Name, Department, and Position member properties, and 0 to the idNumber property.
In an application create three Employee objects to hold the following data.
Name ID Number Department Position
Susan Meyers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
The program should store this data in three objects and then display the data for each employee on screen.
I believe I did the constructors right, but I probably missed something. The only problem I am having is displaying the ID number. But here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HW10CH9_4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void employeeInfoButton_Click(object sender, EventArgs e)
{
// public void People()
Employee employee1 = new Employee();
Employee employee2 = new Employee();
Employee employee3 = new Employee();
employee1.ID = int.Parse(employeeInfoButton.Text);
employee1.Name = "Susan";
employee1.ID = 47899;
employee1.Dept = "Accounting";
employee1.Position = "Vice President";
MessageBox.Show(Employee(employee1.Name));
}
}
class Employee
{
// Field for name, ID, dept, and position
public string name, dept, position;
public int ID;
public string Name
{
get { return name; }
set { name = value; }
}
public string Dept
{
get { return dept; }
set { dept = value; }
}
public string Position
{
get { return position; }
set { position = value; }
}
public int numID
{
get { return ID; }
set { ID = value; }
}
// 1st Construtor parameterless
public Employee()
{
position = "";
dept = "";
ID = 0;
name = "";
}
// 2nd constructor
public Employee(int number, string employeeName, string department, string occupation)
{
number = ID;
employeeName = name;
department = dept;
occupation = position;
}
//3rd constructor
public Employee(int number, string employeeName)
{
number = ID;
employeeName = name;
dept = "";
position = "";
}
}
}
oh I forgot ignore MessageBox.Show(Employee(employee1.Name));
it was suppose to be MessageBox.Show(employee1.Name);

New Topic/Question
Reply



MultiQuote






|