Nicole
2012-12-08 13:32:00 UTC
employee number
employee name
address
wage hours
I have an employee class set up like so:
class Employee
{
const double STATE_TAX = 0.075;
const double FEDERAL_TAX = 0.2;
const double OVERTIME = 1.5;
const int FULL_TIME = 40;
private int hours, otHours;
private double wage, pay, regPay, otPay;
int empNum;
string name, address;
public Employee()
{
empNum = 0;
name = "";
address = "";
wage = 0.00;
hours = 0;
}
public void SetEmpNum(int a)
{
empNum = a;
}
public void SetName(string a)
{
name = a;
}
public void SetAddress(string a)
{
address = a;
}
public void SetWage(double a)
{
wage = a;
}
public void SetHours(int a)
{
hours = a;
}
public int GetEmpNum()
{
return empNum;
}
public string GetName()
{
return name;
}
public string GetAddress()
{
return address;
}
public double GetWage()
{
return wage;
}
public int GetHours()
{
return hours;
}
//CalcSalary Method
//Purpose: to calculate the salary based on overtime and tax
//Paramters: none
//Returns: double pay
public double CalcSalary()
{
if (hours > FULL_TIME)
{
otHours = hours - FULL_TIME;
regPay = FULL_TIME * wage;
otPay = otHours * (wage * OVERTIME);
pay = regPay + otPay;
}
else pay = wage * hours;
return pay = pay - ((STATE_TAX * pay) + (FEDERAL_TAX * pay));
}
}
}
I need to figure out how to read the data from the file and put it into an array of Employee objects.
So far, it looks like this:
public partial class Form1 : Form
{
//initialize variables and constants
private StreamReader data;
string inputString;
string name = "";
int empNum = 0;
string address = "";
string[] payInfo = new string[2];
double wage = 0.00;
int hours = 0;
const int SIZE = 10;
Employee[] myEmployees = new Employee[SIZE];
int count = 0;
int numEmployees = 0;
//array of employees []
//open form
public Form1()
{
InitializeComponent();
}
//tool strip menu - open data file
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "text files (*.txt)|*txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
data = new StreamReader(myStream);
//read data
inputString = data.ReadLine();
if (inputString != null)
{
empNum = int.Parse(inputString);
name = inputString;
address = inputString;
string[] payInfo = inputString.Split();
wage = double.Parse(payInfo[0]);
hours = int.Parse(payInfo[1]);
}
}
}
}
I know I'm missing a lot.. it's not fillng an array of employees or keeping track of the number of employees, which I need.
The end goal is to display the employee name, address, and net wage upon clicking the Next button. I think I have the event handlers set up OK, but I'm struggling with the data/class thing.
Help??