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

Write a program in C#, named DemoJobs for Harold\'s Home Services. The program s

ID: 3594894 • Letter: W

Question

Write a program in C#, named DemoJobs for Harold's Home Services. The program should instantiate serval Job objects and demonstrate their methods. The Job class contains four data fields--description, time, per hour rate charged and total fee. 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 description 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 origional Jobs.

Additional explanation:

In the Main Program:

Create two instance variables of the Job class.

In the first instance use the constructor that takes job description, time and rate.

In the second instance use the constructor that takes the job description and rate only. Then after you have created the second instance you will invoke that instance's set method to set the time for that job.

Create a new instance of the Job class that adds together the first two instances you created. Example: Job combinedJob = job1 + job2

Create a DisplayJob() method that will take as its parameter the combinedJob object instance that was created above and display all of the properties of this combined job. An example command to invoke such a function should be: DisplayJob(combinedJob)

***Example Output****

file:///E:/Old PC BackUp/CSCI 1630/Labs/Lab06/JobDemo/JobDemo/bin/Debug/JobDemo.EXE Infornation about the first job. Job Description: ipe floor. Job Completion Tine: 4.8 hous. Job Rate Per Hou: $8.75 Job Total Cost $42.0 Infornation about the second job. ob Description: paint trinning ob Completion Tine: 36 Job Total Cost$1.131.68 .8.houri. Job Rate Per Houir: S30.75. Infornation abou t the conbined jobs ob Description: wipe floor and paint trimning Job Completion Tine: 41.6 hours Job Rate Per Hour: $19.75. Job Total Cost: $821.60 Press the key to terminate this pro gran.-

Explanation / Answer

/**Job class that constains methods to set description, time and rate.
The method calculateFee updates the fee whenever change of time and rate*/

//Job.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEMOJOBS
{
    class Job
    {
        private string description;
        private double time;
        private double rate;
        private double totalFee;

        //Construcytor to set the description, time and rate
        public Job(string descrition, double time, double rate)
        {

            this.description = descrition;
            this.time = time;
            this.rate = rate;
            //calculate fee
            calculateFee(time, rate);
        }

        public Job()
        {
         
        }

        public void setDescription(string description)
        {
            this.description = description;
        }

        public string getDescription()
        {
            return description;
        }


        public void setTime(double time)
        {
            this.time = time;
            //update totalfee
            calculateFee(time , getRate());
        }

        public double getTime()
        {
            return time;          
        }


        public void setRate(double rate)
        {
            this.rate = rate;
            //update totalfee
            calculateFee(getTime(), rate);
        }
        public double getRate()
        {
            return rate;
          
        }

        public double getFee()
        {
            return totalFee ;

        }
      
      
        private void calculateFee(double time, double rate)
        {
            totalFee = time * rate;
        }


        // Overload + operator to add two Box objects.
        public static Job operator +(Job a, Job b)
        {
            //create temp job object
            Job temp = new Job();
            //set description from a and b objects of Job
            temp.setDescription(a.getDescription() + " and " + b.getDescription());
            //set time
            temp.setTime(a.getTime() + b.getTime());
            //set rate as average of two rates
            temp.setRate((a.getRate() + b.getRate()) / 2.0);
          
            //return temp
            return temp;
        }
    }
}


--------------------------------------------------------------------------------------------------------------------------------------------------------

/**Tester c sharp program that instantiates two objects
of Job and prints the attribute details and test the
overloaidng + operator and print results to concolse*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEMOJOBS
{
    class Program
    {
        static void Main(string[] args)
        {

            //Create two Job objects
            Job joba = new Job("wash windows", 3.5, 25);
            Job jobb = new Job("clean floor", 5.5, 10);

            Console.WriteLine("joba");

            //print joba
            Console.WriteLine("Description : " + joba.getDescription());
            Console.WriteLine("Hours : " + joba.getTime());
            Console.WriteLine("Rate : " + joba.getRate());
            Console.WriteLine("Fee : " + joba.getFee());


            Console.WriteLine("jobb");

            //print jobb
            Console.WriteLine("Description : " + jobb.getDescription());
            Console.WriteLine("Hours : " + jobb.getTime());
            Console.WriteLine("Rate : " + jobb.getRate());
            Console.WriteLine("Fee : " + joba.getFee());


            //Adding two new jobs using + operator overloading
            Job newjob = joba + jobb;

            //print newjob attribute values
            Console.WriteLine("New Job");

            Console.WriteLine("Description : " + newjob.getDescription());
            Console.WriteLine("Hours : " + newjob.getTime());
            Console.WriteLine("Rate : " + newjob.getRate());
            Console.WriteLine("Fee : " + newjob.getFee());


            Console.ReadKey();

        }
    }
}


----------------------------------------------------------------------------------------------------------------------------------

Sample output:

joba
Description : wash windows
Hours : 3.5
Rate : 25
Fee : 87.5
jobb
Description : clean floor
Hours : 5.5
Rate : 10
Fee : 87.5
New Job
Description : wash windows and clean floor
Hours : 9
Rate : 17.5
Fee : 157.5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote