Ask Question
29 November, 17:04

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.

+1
Answers (1)
  1. 29 November, 18:42
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers