Question

Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and...

Using C#

Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields.

Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary.

Create a Worker classes that is derived from Employee and SalaryCalculate class.

  • In Worker class, it includes two field, nYearWked and curSalary, and constructor(s). It defines the CalcYearWorked() function using (current year – yearStartedWked) and save it in the nYearWked variable. It also defines the CalcCurSalary() function that calculates the current year salary by using initial salary with 3% yearly increment.

Create a Manager class that is derived from Worker class.

  • In Manager class, it includes one field: yearPromo and constructor(s). Itincludes 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.

Write an application that reads the workers and managers information from files (“worker.txt” and “manager.txt”) and then creates the dynamic arrays of objects. Prompt the user for current year and display the workers’ and managers’ current information in separate groups: first and last name, ID, the year he/she has been working, and current salary.

In the text file, The first number is the number of workers/managers in the file.

Txt files are aligned as followed

worker.txt

5
Hector
Alcoser
A001231
1999
24000
Anna
Alaniz
A001232
2001
34000
Lydia
Bean
A001233
2002
30000
Jorge
Botello
A001234
2005
40000
Pablo
Gonzalez
A001235
2007
35000

manager.txt

3
Sam
Reza
M000411
1995
51000
2005
Jose
Perez
M000412
1998
55000
2002
Rachel
Pena
M000413
2000
48000
2010

Homework Answers

Answer #1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyNamespace
{
    public class Employee
    {
        private string firstName;

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }
        private string lastName;

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }
        private int wordId;

        public int WordId
        {
            get { return wordId; }
            set { wordId = value; }
        }
        private int yearStartedWked;

        public int YearStartedWked
        {
            get { return yearStartedWked; }
            set { yearStartedWked = value; }
        }
        private double initSalary;

        public double InitSalary
        {
            get { return initSalary; }
            set { initSalary = value; }
        }

        public Employee()
        {
            firstName = "";
            lastName = "";
            wordId = 0;
            yearStartedWked = 0;
            initSalary = 0;
        }

        public Employee(string fN, string lN, int id, int yearStarted, double salary)
        {
            firstName = fN;
            lastName = lN;
            wordId = id;
            yearStartedWked = yearStarted;
            initSalary = salary;
        }

    }
}


\color{blue}\underline{SalaryCalculate.cs:}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyNamespace
{
    public interface SalaryCalculate
    {
        void CalcYearWorked(int currentYear);
        void CalcCurSalary(int currentYear);
    }
}


\color{blue}\underline{Worker.cs:}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyNamespace
{
    public class Worker : Employee, SalaryCalculate
    {
        private int nYearWked;

        public int NYearWked
        {
            get { return nYearWked; }
            set { nYearWked = value; }
        }
        private double curSalary;

        public double CurSalary
        {
            get { return curSalary; }
            set { curSalary = value; }
        }

        public Worker(string fN, string lN, int id, int yearStarted, double salary) : base(fN, lN, id, yearStarted, salary)
        {
        
        }

        public void CalcYearWorked(int currentYear)
        {
            nYearWked = currentYear - YearStartedWked;
        }

        public void CalcCurSalary(int currentYear)
        {
            double salary = InitSalary;
            for (int i = YearStartedWked; i <= currentYear; ++i)
            {
                salary *= 1.03;
            }
            CurSalary = salary;
        }

    }
}


\color{blue}\underline{Manager.cs:}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyNamespace
{
    public class Manager : Worker
    {
        private int yearPromo;

        public int YearPromo
        {
            get { return yearPromo; }
            set { yearPromo = value; }
        }

        public Manager(string fN, string lN, int id, int yearStarted, double salary, int yearPromo)
            : base(fN, lN, id, yearStarted, salary)
        {
            this.yearPromo = yearPromo;
        }

        public void CalcCurSalary(int currentYear)
        {
            double salary = InitSalary;
            for (int i = YearStartedWked; i <= currentYear; ++i)
            {
                if (i < yearPromo)
                    salary *= 1.03;
                else
                    salary *= 1.05;
            }
            CurSalary = salary * 1.2;   // 20% bonus
        }

    }
}


\color{blue}\underline{EmployeeMain.cs:}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace MyNamespace
{
    class EmployeeMain
    {
        public static void Main()
        {
            List<Worker> employees = new List<Worker>();
            using (StreamReader sr = new StreamReader(new FileStream("worker.txt", FileMode.Open)))
            {
                string line;
                while((line = sr.ReadLine()) != null)
                {
                    string[] words = line.Split(' ');
                    employees.Add(new Worker(words[0], words[1], Convert.ToInt32(words[2]), Convert.ToInt32(words[3]), Convert.ToDouble(words[4])));
                }
            }
            List<Manager> managers = new List<Manager>();
            using (StreamReader sr = new StreamReader(new FileStream("manager.txt", FileMode.Open)))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] words = line.Split(' ');
                    managers.Add(new Manager(words[0], words[1], Convert.ToInt32(words[2]), Convert.ToInt32(words[3]), Convert.ToDouble(words[4]), Convert.ToInt32(words[5])));
                }
            }
            Console.Write("Enter current year: ");
            int year = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < employees.Count; ++i)
            {
                employees[i].CalcYearWorked(year);
                employees[i].CalcCurSalary(year);
                Console.WriteLine("Worker: " + employees[i].LastName + ", " + employees[i].FirstName + "'s salary is: " + employees[i].CurSalary + " and worked a total of " + employees[i].NYearWked + " years.");
            }
            for (int i = 0; i < managers.Count; ++i)
            {
                managers[i].CalcYearWorked(year);
                managers[i].CalcCurSalary(year);
                Console.WriteLine("Manager: " + managers[i].LastName + ", " + managers[i].FirstName + "'s salary is: " + managers[i].CurSalary + " and worked a total of " + managers[i].NYearWked + " years.");
            }
        }
    }
}


\color{blue}\underline{worker.txt:}

cristiano ronaldo 7 2004 100000
lionel messi 10 2006 80000
gareth bale 11 2008 65000

\color{blue}\underline{manager.txt:}

arsene wenger 1 1994 25000 2000
jose morinho 2 2000 50000 2006

Output Screenshot:-

----------------------------------------------------------------

Please give me a UPVOTE. Thank you :)

Know the answer?
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
Similar Questions
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name...
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name self._salary = salary def my_name(self): return self._name def wage(self): return self._salary/26 # fortnight pay Define a new subclass of Employee called Worker. A worker has a manager, who is another employee; their manager is given as an argument to the constructor. You should define a method get_manager that returns the worker’s manager. boss = Employee('Mr. Burns', 1000000) worker = Worker('Waylon Smithers', 2500, boss) Define...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
Create a C# application You are to create a class object called “Employee” which included eight...
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week. regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods:  constructor  properties  CalcPay(): Calculate the regular...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h andRun.cpp to separate class header and implementation. In this program, we are going to create a small scale Telivision Management System. A) Create a class Episode with following variables: char* episode_name, char* episode_venue, char episode_date[22] and char episode_time[18]. Input format for episode_date: dd-mm-yyyy Input format for episode_time: hh:mm am/pm B) Implement default constructor and overloaded constructor. Print “Default Constructor Called” and “Overloaded Constructor Called”...
Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked...
Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked onto a linked list. The data structure should have the following fields: a. First Name (firstName) b. Last Name (lastName) c. Employee ID (id) d. Start Year (startYear) e. Starting Salary (startSalary) f. Current Salary (currentSalary) g. next Create a library of functions that operate on this data structure. The source code for the functions should be in lastname_employeerec.c and the function prototypes should...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>    #include <cstdlib> #include "QueueADT.h" using namespace std; // Definition of the node template <class ItemType> struct NodeType {        ItemType info;        NodeType<ItemType> *next; }; template <class ItemType> class LinkedQueueType: public QueueADT<ItemType> { public:        // Constructor        LinkedQueueType();           // Default constructor.           // Post: An empty queue has been created. queueFront = NULL;           //       queueBack = NULL;...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...