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

  • SEARCH
  • Home
  • 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 8956787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:51:13+00:00 2026-06-15T14:51:13+00:00

I am having a problem calling a method from my Employee class, my code

  • 0

I am having a problem calling a method from my Employee class, my code is below, any suggestions are appreciated.

private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void openToolStripMenuItem_Click(object sender, EventArgs e)
    {
        int num = 0;
        string str = null;
        string str2 = null;
        double num2 = 0.0;
        double num3 = 0.0;

        //code to allow a file to be browed for and opened
        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)
            {
                //the streamreader is named 'data'
                data = new StreamReader(myStream);

                string fileData = "";
                while (fileData != null)
                {
                    fileData = data.ReadLine();
                    if (fileData != null)
                    {
                        num = int.Parse(fileData);
                        str = data.ReadLine();
                        str2 = data.ReadLine();
                        string[] strArray = data.ReadLine().Split(new char[0]);
                        num3 = double.Parse(strArray[0]);
                        num2 = double.Parse(strArray[1]);
                        EmployeeData[count++] = Convert.ToString(new Employee(num, str, str2, num2, num3));
                    }
                }
                NextBtn.Enabled = true;
                numEmployees = count;
                count = 0;
                nameTxtBox.Text = EmployeeData[count].GetName();
                addressTxtBox.Text = Convert.ToString(EmployeeData[count].GetAddress());
                string str4 = string.Format("{0:C}", EmployeeData[count].calcPay());
                payTxtBox.Text = str4;
            }
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        count++;
        if (count < this.numEmployees)
        {
            nameTxtBox.Text = EmployeeData[count].GetName();
            addressTxtBox.Text = EmployeeData[count].GetAddress();
            string str = string.Format("{0:C}", EmployeeData[count].calcPay());
            payTxtBox.Text = str;
        }
        else
        {
            NextBtn.Enabled = false;
            nameTxtBox.Clear();
            addressTxtBox.Clear();
            payTxtBox.Clear();
        }

    }


 }
}

my Employee method looks like this:

public class Employee
{
    private string employeeAddress;
    private string employeeName;
    private int employeeNumber;
    private const double FED_TAX = 0.2;
    private const int FULL_TIME = 40;
    private double hourlyWage;
    private double hoursWorked;
    private const double OVER_TIME = 1.5;
    private const double STATE_TAX = 0.075;

    public Employee()
    {
        employeeNumber = 0;
        employeeName = "";
        employeeAddress = "";
        hourlyWage = 0.0;
        hoursWorked = 0.0;
    }

    public Employee(int _num, string _name, string _address, double _hours, double _wage)
    {
        employeeNumber = _num;
        employeeName = _name;
        employeeAddress = _address;
        hourlyWage = _wage;
        hoursWorked = _hours;
    }

    public double calcPay()
    {
        double pay = hoursWorked * hourlyWage;
        double ot = hoursWorked - FULL_TIME;
        if (ot > 0.0)
        {
            pay += ot * (hourlyWage * OVER_TIME);
        }
        double tax1 = pay * FED_TAX;
        double tax2 = pay * STATE_TAX;
        return ((pay - tax1) - tax2);
    }

    public string GetAddress()
    {
        return employeeAddress;
    }

    public double GetHours()
    {
        return hoursWorked;
    }

    public string GetName()
    {
        return employeeName;
    }

    public double GetWage()
    {
        return hourlyWage;
    }
}
}
  • 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-06-15T14:51:14+00:00Added an answer on June 15, 2026 at 2:51 pm

    Your issue appears to be that your EmployeeData collection is of type string, rather than Employee, thereby losing all structural information for your class instances. You need to change the type of the collection, as well as the following line from:

     EmployeeData[count++] = Convert.ToString(new Employee(num, str, str2, num2, num3));
    

    …to:

     EmployeeData[count++] = new Employee(num, str, str2, num2, num3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem with JNI, calling a method from C++ to Java.
I am having trouble calling a specific method from another class in my app.
I am having a problem when calling session bean method passing method parameters from
I am having a problem calling a model property from my view. I may
I'm having a problem with calling a function in a different class in QT
I'm having a big problem when calling a web service from my WPF application.
I'm having trouble calling a method in one Struts action from a method in
I am having a problem with Vlad on windows. After calling rake vlad:deploy I
I'm having problem with datagrid view. I have attached an image with the code
I am having problem with drawing multiple lines during repaint. The code is as

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.