Question

In: Computer Science

C# (Thank you in advance) Create an Employee class with five fields: first name, last name,...

C# (Thank you in advance)

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.

**Following is the content of the text files**

________________

manager.txt :

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

_______________

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

Solutions

Expert Solution

Code:-

/// Employee.cs ///

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;
}

}
}

/// 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);
}
}

/// 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;
}

}
}

/// 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
}

}
}

/// Main.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.");
}
}
}
}

/// manager.txt ///

Sam Reza 000411 1995 51000 2005
Jose Perez 000412 1998 55000 2002
Rachel Pena 000413 2000 48000 2010

/// worker.txt ///

Hector Alcoser 001231 1999 24000
Anna Alaniz 001232 2001 34000
Lydia Bean 001233 2002 30000
Jorge Botello 001234 2005 40000
Pablo Gonzalez 001235 2007 35000

Output:-

Please UPVOTE thank you...!!!


Related Solutions

In C# please and thanks so much, Create an Employee class with five fields: first name,...
In C# please and thanks so much, 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...
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...
Design and implement a C++ Application that: Interactively input: Employee First Name Employee Last Name Employee...
Design and implement a C++ Application that: Interactively input: Employee First Name Employee Last Name Employee id Employee hours worked per week Employee Pay Rate Menu with Option to: Print out Employee Report in the following report format Search for an Employee Display the Report in Sorted based on Last Name or ID Calculate the Pay Quit Criteria: Be sure to use Parallel Arrays to Store the Employee Information Output must be formatted and line up with the column header...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and havekids (Boolean) variables. You have to create constructors and prosperities for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from the “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the people's information from “PersonInfo.txt” file and save them into the array. Give the user the ability to...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth Create a table ‘ClassInfo’ table: ID Class Name Class Description Create a table ‘RegisteredClasses’ table: StudentID ClassID The RegisteredClasses table should have a foreign key relationship to StudentInfo and ClassInfo tables for the respective IDs. Also the IDs in StudentInfo and ClassInfo need to be primary keys. When you submit the file your email should also contain the following SQL Queries: Query to show...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name,...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name, last name, and hourly pay rate (use of string datatype is not allowed). Create an array of five Employee objects. Input the data in the employee array. Write a searchById() function, that ask the user to enter an employee id, if its present, your program should display the employee record, if it isn’t there, simply print the message ”Employee with this ID doesn’t exist”....
C++ Change the program to take user input for first name and last name for five...
C++ Change the program to take user input for first name and last name for five employees. Add a loop to read the first name and last name. // EmployeeStatic.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> #include <string> using namespace std; class Employee { public:    Employee(const std::string&, const std::string&); // constructor    ~Employee(); // destructor    std::string getFirstName() const; // return first name    std::string getLastName() const; // return...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT