Ask Question
3 January, 13:34

Create a constructor that requires parameters for the job number and estimated hours only. Also, include a ToString () method that overrides the Object class's ToString () method and returns a string that contains the class name (using GetType ()) and the job's data field values. The Job class has a child class named RushJob that includes an auto-implemented property, ExtraCharge, which holds an additional charge for the job. For the RushJob class, you need to create a constructor that accepts the job number, estimated hours, and extra charge. Also, override the Object class's ToString () method and return a string that contains the class name and all data field values, as well as the total price (i. e., price + extra charge). Finally, create an application class named JobDemo that instantiates one Job object and one RushJob object. Then call ToString () method and display the info of each object on the screen.

+3
Answers (1)
  1. 3 January, 17:25
    0
    See explaination

    Explanation:

    Job. cs

    using System;

    using System. Collections. Generic;

    using System. Linq;

    using System. Text;

    using System. Threading. Tasks;

    namespace JobApp

    {

    public class Job

    {

    private int jobNumber;

    private int estimatedHours;

    private double price;

    public Job (int jobNum, int estHrs)

    {

    jobNumber = jobNum;

    estimatedHours = estHrs;

    CalculatePrice ();

    }

    public int JobNumber { get; set; }

    public int EstimatedHours

    {

    get { return estimatedHours; }

    set { estimatedHours = value; CalculatePrice (); }

    }

    private void CalculatePrice ()

    {

    price = estimatedHours * 45;

    }

    public virtual double getPrice ()

    {

    return price;

    }

    public override string ToString ()

    {

    return GetType () + "/n" +

    "Job No: " + jobNumber + "/n" +

    "Est. Hrs.: " + estimatedHours + "/n" +

    "Price: $" + price;

    }

    }

    }

    RushJob. cs

    using System;

    using System. Collections. Generic;

    using System. Linq;

    using System. Text;

    using System. Threading. Tasks;

    namespace JobApp

    {

    public class RushJob : Job

    {

    private double additionalCharge;

    public RushJob (int jobNum, int estHrs, double additionalCharge) : base (jobNum, estHrs)

    {

    this. additionalCharge = additionalCharge;

    }

    public override double getPrice ()

    {

    return this. additionalCharge + base. getPrice ();

    }

    public override string ToString ()

    {

    return

    base. ToString () + "/n" +

    "Additional Charge: $" + this. additionalCharge + "/n" +

    "Total Price: $" + getPrice ();

    }

    }

    }

    JobDemo. cs

    using System;

    using System. Collections. Generic;

    using System. Linq;

    using System. Text;

    using System. Threading. Tasks;

    namespace JobApp

    {

    class JobDemo

    {

    static void Main (string[] args)

    {

    Job job = new Job (101, 10);

    Console. WriteLine (job. ToString ());

    Job rushJob = new RushJob (102, 15, 5);

    Console. WriteLine ("/n"+rushJob. ToString ());

    Console. ReadKey ();

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create a constructor that requires parameters for the job number and estimated hours only. Also, include a ToString () method that ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers