Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code: - / / / Employee.cs / / / using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyNamespace { public class Employee

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 employees = new List();
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 managers = new List();
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 0004111995510002005
Jose Perez 0004121998550002002
Rachel Pena 0004132000480002010
/// worker.txt ///
Hector Alcoser 001231199924000
Anna Alaniz 001232200134000
Lydia Bean 001233200230000
Jorge Botello 001234200540000
Pablo Gonzalez 001235200735000
I need to compile this in vs code for C#

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

I am paid fairly for the work I do.

Answered: 1 week ago

Question

I receive the training I need to do my job well.

Answered: 1 week ago