Note that there are some explanatory texts on larger screens.

plurals
  1. POThere is no error in my code, but the output that should be displaying is not being displayed
    text
    copied!<p>I am not really sure why but when I put break points in and stepped through my code each of the properties return either a null or 0 when they should be the values I put in the main where I mad the instances of the class.</p> <p>This is my main</p> <pre><code>namespace DemoJobs { class Program { static void Main(string[] args) { string desc; decimal rate, time, total; Job job1 = new Job("Pour Driveway", 8m, 50.00m); Job job2 = new Job("Instal New Windows", 18m, 120m); Job job3 = job1 + job2; Console.WriteLine("The {0} job will take {1} hours, costing {2} per hour with a total of {3}", job1.Description, job1.Time, job1.Rate.ToString("C"), job1.Total.ToString("C")); Console.WriteLine("The {0} job will take {1} hours, costing {2} per hour with a total of {3}", job2.Description, job2.Time, job2.Rate.ToString("C"), job2.Total.ToString("C")); Console.WriteLine("The {0} job will take {1} hours, costing {2} per hour with a total of {3}", job3.Description, job3.Time, job3.Rate.ToString("C"), job3.Total.ToString("C")); Console.ReadLine(); } } } </code></pre> <p>This is my class</p> <pre><code>namespace DemoJobs { public class Job { // variables private string _description; private decimal _time, _rate, _total; // property for the job description public string Description { get { return _description; } set { _description = value; } } // property for the total job time public decimal Time { get { return _time; } set { _time = value; CalcTotal(); } } // property for the jobs hourly rate public decimal Rate { get { return _rate; } set { _rate = value; CalcTotal(); } } // read-only property for the job total public decimal Total { get { return _total; } } // method to calculate the total for the job public decimal CalcTotal() { _total = _rate * _time; return _total; } // constructor public Job(string description, decimal time, decimal rate) { Description = _description; Time = _time; Rate = _rate; } public static Job operator +(Job job1, Job job2) { string newDescription = job1.Description + " and " + job2.Description; decimal newTime = job1.Time + job2.Time; decimal newRate = (job1.Rate + job2.Rate) / 2; decimal newTotalFee = newRate * newTime; return (new Job(newDescription, newTime, newRate)); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload