a. Write a program named DEMOJOBS for Harold’s Home Services. The program should
ID: 665796 • Letter: A
Question
a. Write a program named DEMOJOBS for Harold’s Home Services. The program should instantiate several Job objects and demonstrate their methods. The Job class contains four data fields—description (for example, “wash windows”), time in hours to complete (for example, 3.5), per-hour rate charged (for example, $25.00), and total fee (hourly rate times hours). Include properties to get and set each field except the total fee—that field will be read-only, and its value is calculated each time either the hourly fee or the number of hours is set. Overload the + operator so that two Jobs can be added. The sum of two Jobs is a new Job containing the descriptions of both original Jobs (joined by “and”), the sum of the time in hours for the original Jobs, and the average of the hourly rate for the original Jobs.
b. Harold has realized that his method for computing the fee for combined jobs is not fair. For example, consider the following:
• His fee for painting a house is $100 per hour. If a job takes 10 hours, he earns $1000.
• His fee for dog walking is $10 per hour. If a job takes 1 hour, he earns $10.
• If he combines the two jobs and works a total of 11 hours, he earns only the average rate of $55 per hour, or $605. (Farrell 433-434)
Farrell, Joyce. Microsoft® Visual C# 2012: An Introduction to Object-Oriented Programming, 5e, 5th Edition. Cengage Learning, 03/2013. VitalBook file.
The citation provided is a guideline. Please check each citation for accuracy before use.
C# console application
Explanation / Answer
Required C# console application is being created which is having the job class.Include this two files in the project.
Job class is created as per question. Execution is done in program.cs.
------------------------------------------------------------------------------
Job.cs
---------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoJobs
{
public class Job
{
private string description;
private double timeInHours;
private double perHourRateCharged;
private double totalFee;
public string Description
{
get { return this.description; }
set { this.description = value; }
}
public double TimeInHours
{
get { return this.timeInHours; }
set
{
this.timeInHours = value;
this.totalFee = this.CalculateTotalFee();
}
}
public double PerHourRateCharged
{
get { return this.perHourRateCharged; }
set
{
this.perHourRateCharged = value;
this.totalFee = this.CalculateTotalFee();
}
}
public double TotalFee
{
get
{
this.totalFee = this.CalculateTotalFee();
return this.totalFee;
}
}
public static Job operator +(Job job1, Job job2)
{
Job job = new Job
{
Description = job1.Description + " And " + job2.Description,
TimeInHours = job1.TimeInHours + job2.TimeInHours,
PerHourRateCharged = (job1.PerHourRateCharged + job2.PerHourRateCharged)/2
};
return job;
}
private double CalculateTotalFee()
{
return (this.timeInHours * this.perHourRateCharged);
}
}
}
-----------------------------------------------------------------------------------------------------------------
Program.cs
---------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoJobs
{
class Program
{
static void Main(string[] args)
{
Job job1 = new Job
{
Description = "Painting a house",
PerHourRateCharged = 100,
TimeInHours = 10
};
Console.WriteLine(" Description : [{0}], Per-hour rate charged :[{1}], Time in hours:[{2}], Total fee :[{3}]",
job1.Description, job1.PerHourRateCharged, job1.TimeInHours, job1.TotalFee);
Job job2 = new Job
{
Description = "Dog walking",
PerHourRateCharged = 10,
TimeInHours = 1
};
Console.WriteLine(" Description : [{0}], Per-hour rate charged :[{1}], Time in hours:[{2}], Total fee :[{3}]",
job2.Description, job2.PerHourRateCharged, job2.TimeInHours, job2.TotalFee);
Job job = job1 + job2;
Console.WriteLine(" Description : [{0}], Per-hour rate charged :[{1}], Time in hours:[{2}], Total fee :[{3}]",
job.Description, job.PerHourRateCharged, job.TimeInHours, job.TotalFee);
Console.WriteLine("Press [Enter] to exit..");
Console.ReadLine();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.