Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c# Write compile and test a program named DemoJobs. The program will instantiate

ID: 3682755 • Letter: C

Question

c#

Write compile and test a program named DemoJobs. The program will instantiate three Job objects and demonstrate their methods as described below.

1. The Job class contains four private data fields: description, time, hourly rate, and total fee.

2. The description, time, and hourly rate fields will have public get and set properties. The total fee field will be read-only and have only a get property. The value of the total fee field will be calculated each time either the time or hourly rate is set.

3. The + operator will be overloaded so that two jobs can be added. The sum of two jobs is a new job containing:

a. The descriptions of both jobs joined by “and”.

b. The sum of the two times.

c. The hourly rate will be a weighted average of the two hourly rates. Be sure to use variables of the appropriate types, and to use meaningful names for all variables and methods

Explanation / Answer

using System;

public class AddJobs
{
private double totalFee;

public AddJobs(double TotalFee)
{
totalFee = TotalFee;
}

public static void Main()
{
Job job1 = new Job("washing windows", 5.00, 25.00);
Job job2 = new Job("walking a dog", 3.00, 11.00);
Job job3;
job3 = job1 + job2;

Console.WriteLine("The first job's description: {0} Total time needed to complete the job: {1} hours Hourly fee: {2} per hour", job1.Description, job1.Time, job1.Rate.ToString("C"));
TotalPay(job1);

Console.WriteLine("The second job's description: {0} Total time needed to complete the job: {1} hours Hourly fee: {2} per hour", job2.Description, job2.Time, job2.Rate.ToString("C"));
TotalPay(job2);

Console.WriteLine("The third job's description: {0} Total time needed to complete the job: {1} hours Hourly fee: {2} per hour", job3.Description, job3.Time, job3.Rate.ToString("C"));
TotalPay(job3);
}

public static void TotalPay(Job method)
{

double totalFee = method.Rate * method.Time;
Console.WriteLine("The total fee is: {0}", totalFee.ToString("C"));
}
}

class Job
{

public Job(string description, double time, double rate)
{
Description = description;

Time = time;

Rate = rate;
}

public static Job operator +(Job first, Job second)
{
string newDescription = first.Description + " and " + second.Description;

double newTime = first.Time + second.Time;

double newRate = (first.Rate + second.Rate) / 2;

double newTotalFee = newRate * newTime;

return (new Job(newDescription, newTime, newRate));
}

public string Description { get; set; }
public double Time { get; set; }
public double Rate { get; set; }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote