Question: THis is in C#. I am getting an error on line 24 of PartTimeEmployee, it says that it is trying to initalize a new object
THis is in C#. I am getting an error on line 24 of PartTimeEmployee, it says that it is trying to initalize a new object class. I'm unsure how to fix it. And on Program ,ines 23 and 24 I am also getting an error. Its telling me I cannot convert from part time to employee. How do I remmedey both of these isssues?
PROGRAM.CS
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace dropbox06 { class Program { static void Main(string[] args) { List
FullTimeEmployee fe1 = new FullTimeEmployee("111", "Alice", 67888.00m); FullTimeEmployee fe2 = new FullTimeEmployee("22", "Bob", 67555.00m);
PartTimeEmployee pe1 = new PartTimeEmployee("333", "Chuck", 22.12m, 20m); PartTimeEmployee pe2 = new PartTimeEmployee("444", "Dan", 23.33m, 18.45m);
allEmployees.Add(fe1); allEmployees.Add(fe2); allEmployees.Add(pe1); allEmployees.Add(pe2);
foreach(Employee emp in allEmployees) { Console.WriteLine(emp); } Console.ReadKey(); } } }
PARTTIMEEMPLOYEE.CS
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace dropbox06 { class PartTimeEmployee { private decimal hourlyWahe; private decimal hoursWorked; public decimal HourlyWage { get { return HourlyWage; } set { HourlyWage = value; } } public decimal HoursWorked { get { return hoursWorked; } set { HourlyWage = value; } } public PartTimeEmployee(string employeeId, string employeeName, decimal hourlyWage, decimal hoursWorked) :base(employeeId, employeeName) { this.HourlyWage = hourlyWage; this.hoursWorked = hoursWorked; } public decimal GetWeeklyPay() { decimal payAmount; payAmount = HoursWorked * HourlyWage; return payAmount; } public override string ToString() { return base.ToString();) { string str; str = base.ToString() + string.Format("Pay amount: {0:C}", GetWeeklyPay()); return str; } } } }
FULLTIMEEMPLOYEE.CS
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace dropbox06 { class FullTimeEmployee : Employee { private decimal annualSalary;
public decimal AnnualSalary { get { return annualSalary; } set {annualSalary= value; } } public FullTimeEmployee(string employeeId, string employeeName, decimal annualSalary) :base(employeeId, employeeName) { this.annualSalary = annualSalary; } public decimal GetWeeklyPay() { decimal payAmount; payAmount = AnnualSalary / 52; return payAmount; } public override string ToString() { string str; str = base.ToString() + string.Format("Pay amount: {0:C}", GetWeeklyPay()); return str; } } }
PARTTIME.CS
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace dropbox06 { class Employee { private string employeeId; private string employeeName; public string EmployeeId { get { return employeeId; } set { employeeId = value; } } public string EmployeeName { get { return employeeName; } set { employeeName = value; } } public Employee(string employeeId, string employeeName) { this.employeeId = employeeId; this.employeeName = employeeName; } public override string ToString() { string str; str = string.Format("ID: {0} Name: {1}", employeeId, EmployeeName); return str; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
