Question

C# Language please. Create an “Employee” class with six fields: first name, last name, workID, yearStartedWked,...

C# Language please.

Create an “Employee” class with six fields: first name, last name, workID, yearStartedWked, initSalary, and curSalary. It includes constructor(s) and properties to initialize values for all fields (curSalary is read-only). It also includes a calcCurSalary function that assigns the curSalary equal to initSalary.

Create a “Worker” classes that are derived from Employee class.  In Worker class, it has one field, yearWorked. It includes constructor(s) and properties. It also includes two functions: first, calcYearWorked function, it takes one parameter (currentyear) and calculates the number of year the worker has been working (current year–yearStartedWked) and save it in the yearWorked variable. Second, the calcCurSalary function that calculate the current year salary by overriding the base class function using initial salary with 3% yearly increment.

Create a “Manager” classes that are derived from Worker class.  In Manager class, it includes one field: yearPromo. It includes the constructor(s) and property. It also includes a calcCurSalary function that calculate the current year salary by overriding the base class function using initial salary with 5% yearly increment plus 10% bonus. The manager’s salary calculates in two parts. It calculates as a worker before the year promoted and as a manager after the promotion.

Create an “EmployeeDemo” class. It includes three functions:

1. In the main function, the program calls the readData() function to get the data from file and calls the objSort() function to sort the array of objects. Then, the program prompts user to enter the range of current salary that user want to see and display the employee’s information whose current salary is in the range in a descending order.

2. readData(): it reads the workers and managers information from files (“worker.txt” and “manager.txt”) and then creates the dynamic arrays of objects to save the data. Then, it prompts user for the current year to calculate the yearWorked and currentSalary.

3. objSort(): this function accepts an array of object as a parameter and sort the array by current salary in descending order

Worker text file:
Agustin White A001231 1999 24000
Leslie Hernandez A001232 2001 34000
Robert Huerta A001233 2002 30000
John Luna A001234 2005 40000
Rey Green A001235 2007 35000
Manager text file:
Jay Mendoza M000411 1995 51000 2005
Sam Zuniga M000412 1998 55000 2002 
Jacob Tatum M000413 2000 48000 2010
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Program

using System;
using System.IO;

namespace EmploYeeDetailsInCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create an array
            Employee[] employees= new Employee[8];
            //Call function to read data
            readData(employees);
            //Sort in descending order
            objSort(employees);
            //Salary for search
            Console.Write("\nEnter salary to search: ");
            double amt = Convert.ToDouble(Console.ReadLine());
            //Display details
            for(int i = 0; i < 8; i++)
            {
                if (employees[i].CurrentSalary >= amt)
                {
                    Console.WriteLine(employees[i].FirstName + " " + employees[i].LastName + " " +
                        employees[i].WORKID + " " + employees[i].CurrentSalary);
                }
            }
        }
        //Function to read file data and save data from file to array
        //Then prompt for year and calculate salary accordingly
        static void readData(Employee[] employees)
        {
            int i = 0;
            using(StreamReader reader=new StreamReader("C:/Users/deept/source/repos/EmploYeeDetailsInCSharp/EmploYeeDetailsInCSharp/worker.txt"))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    string[] lineData = line.Split(' ');
                    employees[i] = new Worker(lineData[0], lineData[1], lineData[2], Convert.ToInt32(lineData[3]), Convert.ToDouble(lineData[4]));
                    i++;
                }
            }
            using (StreamReader reader = new StreamReader("C:/Users/deept/source/repos/EmploYeeDetailsInCSharp/EmploYeeDetailsInCSharp/manager.txt"))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    string[] lineData = line.Split(' ');
                    employees[i] = new Manager(lineData[0], lineData[1], lineData[2], Convert.ToInt32(lineData[3]), Convert.ToDouble(lineData[4]), Convert.ToInt32(lineData[5]));
                    i++;
                }
            }
            for(int j = 0; j < i; j++)
            {
                Console.Write("Enter " + employees[j].FirstName + " current year: ");
                int yr = Convert.ToInt32(Console.ReadLine());
                if(employees[j].GetType() == typeof(Worker))
                {
                    ((Worker)employees[j]).calcYearWorked(yr);
                    ((Worker)employees[j]).calcCurSalary();
                }
                else
                {
                    ((Manager)employees[j]).calcYearWorked(yr);
                    ((Manager)employees[j]).calcCurSalary();
                }
            }
        }
        //Sort descending order of salary
        static void objSort(Employee[] employees)
        {
            for(int i = 0; i < employees.Length - 1; i++)
            {
                for(int j = 0; j < employees.Length; j++)
                {
                    if (employees[i].CurrentSalary < employees[j].CurrentSalary)
                    {
                        Employee temp = employees[i];
                        employees[i] = employees[j];
                        employees[j] = temp;
                    }
                }
            }
        }
    }
    //Create a class Employee
    class Employee
    {
        //Data fields
        private string firstName, lastName;
        private string workID;
        private int yearStartedWked;
        private double initSalary;
        protected double curSalary;
        //Default constructor
        public Employee()
        {
            firstName = lastName = workID = "";
            yearStartedWked = 0;
            initSalary = curSalary = 0;
        }
        //Parameterized constructor
        public Employee(string fname,string lname,string id,int sYear,double initSal)
        {
            firstName = fname;
            lastName = lname;
            workID = id;
            yearStartedWked = sYear;
            initSalary = initSal;
        }
        //Accessors and mutators
        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                firstName = value;
            }
        }
        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                lastName = value;
            }
        }
        public string WORKID
        {
            get
            {
                return workID;
            }
            set
            {
                workID= value;
            }
        }
        public int StartYear
        {
            get
            {
                return yearStartedWked;
            }
            set
            {
                yearStartedWked = value;
            }
        }
        public double InitSalary
        {
            get
            {
                return initSalary;
            }
            set
            {
                initSalary = value;
            }
        }
        public double CurrentSalary
        {
            get
            {
                return curSalary;
            }
        }
        //Function to calculate current salary
        public virtual void calcCurSalary()
        {
            curSalary = initSalary;
        }
    }
    //Derived class
    class Worker : Employee
    {
        //Mamber variable
        private int yearWorked;
        //Default constructor
        public Worker()
        {

        }
        //Parametrized constructor
        public Worker(string fname, string lname, string id, int sYear, double initSal)
        {
            this.FirstName = fname;
            this.LastName = lname;
            this.WORKID = id;
            this.StartYear = sYear;
            this.InitSalary = initSal;
        }
        public void calcYearWorked(int curYear)
        {
            yearWorked = curYear - this.StartYear;
        }
        public int getYearworked()
        {
            return yearWorked;
        }
        public override void calcCurSalary()
        {
            this.curSalary = this.InitSalary;
            for (int i = 0; i < yearWorked; i++)
            {
                this.curSalary+= CurrentSalary * .03;
            }
          
        }
    }
    //Derived class
    class Manager :Worker
    {
        //Mamber variable
        private int yearPromo;
        //Default constructor
        public Manager()
        {

        }
        //Parametrized constructor
        public Manager(string fname, string lname, string id, int sYear, double initSal, int yr)
        {
            this.FirstName = fname;
            this.LastName = lname;
            this.WORKID = id;
            this.StartYear = sYear;
            this.InitSalary = initSal;
            yearPromo = yr;
        }
        //Salary setting
        public override void calcCurSalary()
        {
            this.curSalary = this.InitSalary;
            for (int i = 0; i < StartYear-yearPromo; i++)
            {
                this.curSalary += CurrentSalary * .03;
            }
            for (int i = yearPromo; i <(yearPromo+getYearworked()) ; i++)
            {
                this.curSalary += CurrentSalary * .05;
                this.curSalary += CurrentSalary * .1;
            }
        }
    }
}

Output

Enter Agustin current year: 2018
Enter Leslie current year: 2018
Enter Robert current year: 2018
Enter John current year: 2018
Enter Rey current year: 2018
Enter Jay current year: 2018
Enter Sam current year: 2018
Enter Jacob current year: 2018

Enter salary to search: 60000
Sam Zuniga M000412 981753.309729765
Jay Mendoza M000411 1402670.98460212
Jacob Tatum M000413 642268.989330358

Add a comment
Know the answer?
Add Answer to:
C# Language please. Create an “Employee” class with six fields: first name, last name, workID, yearStartedWked,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C# Create an “EmployeeDemo” class. It includes three functions: 1. In the main function, the...

    In C# Create an “EmployeeDemo” class. It includes three functions: 1. In the main function, the program calls the readData() function to get the data from file and calls the objSort() function to sort the array of objects. Then, the program prompts user to enter the range of current salary that user want to see and display the employee’s information whose current salary is in the range in a descending order. 2. readData(): it reads the workers and managers information...

  • Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean)...

    Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean) variables. You have to create constructors and properties for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from a “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the peoples information from “PersonInfo.txt” file and saves them into the array. In C# Give the user the ability to...

  • In one file create an Employee class as per the following specifications: three private instance variables:...

    In one file create an Employee class as per the following specifications: three private instance variables: name (String), startingSalary (int), yearlyIncrement (int) a single constructor with three arguments: the name, the starting salary, and the yearly increment. In the constructor, initialize the instance variables with the provided values. get and set methods for each of the instance variables. A computation method, computeCurrentSalary, that takes the number of years in service as its argument. The method returns the current salary using...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • E2a: Create a class called Employee that includes three pieces of information as data members---a first...

    E2a: Create a class called Employee that includes three pieces of information as data members---a first name (char array), last name (char array) and a monthly salary (integer). Your class should have a constructor that initializes the three data members. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display...

  • Create a class called Employee that includes three instance variables—a first name, a last name, and...

    Create a class called Employee that includes three instance variables—a first name, a last name, and a monthly salary. Code the default (no-args, empty) constructor. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value.

  • Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...

    Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT