I posted this before but I didn\'t specify that this is for a C# programming cla
ID: 3715461 • Letter: I
Question
I posted this before but I didn't specify that this is for a C# programming class.
Create an application named JobDemo that declares and uses Job Job class holds job information for a home repair service. The c properties that include a job number, customer name, job hours, and price for the job, Create a the data except price. Include auto-implemented properties for t customer name, and job description, but not for hours or price, the price field value is calculated as estimated hours times $45.00 whenever the hours value is set. Also create the following for the class: a. The objects lass has five 3. description, estimated rs for all constructor that requires paramete he job number 47 . An EqualsO method that determines two Jobs are equal if they have the same ob number . A GetHashCode O method that returns the job number . A ToString O method that returns a string containing all job information The JobDemo application declares a few Job objects, sets their values, and demonstrates that all the methods work as expected. b. Using the Job class you created in Exercise 3a, write a new application named JobDemo2 that creates an array of five Job objects. Prompt the user for values for each Job. Do not allow duplicate job numbers; force the user to reenter the job when a duplicate job number is entered. When five valid objects have been entered display them all, plus a total of all prices. c. Create a RushJob class that derives from Job. A RushJob has a $150.00 premium that is added to the normal price of the job. Override any methods in the parent class as necessary. Write a new application named JobDemo3 that creates an array of five RushJobs. Prompt the user for values for each, and do not allow duplicate ob numbers. When five valid RushJob objects have been entered, display them all plus a total of all prices. d. Make any necessary modifications to the RushJob class so that it can be sorted by job number. Modify the JobDemo3 application so the displayed orders have been sorted. Save the application as JobDemo4.Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace ConsoleApplication1
{
class Job : System.Object
{
public int JobNumber { get; set; }
public string CustomerName { get; set; }
public string JobDescription { get; set; }
public int EstimatedHours { get; set; }
public int JobPrice { get; set; }
public Job(int jobNumber, string customerName, string jobDescription, int extimatedHours)
{
JobNumber = jobNumber;
CustomerName = customerName;
JobDescription = jobDescription;
EstimatedHours = extimatedHours;
JobPrice = 45 * extimatedHours;
}
//overiding the Equals method
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
Job job = obj as Job;
if (job == null)
{
return false;
}
return JobNumber == job.JobNumber;
}
//overriding the GetHashCode method
public override int GetHashCode()
{
return JobNumber;
}
//overriding the To string method
public override string ToString()
{
return string.Format("JobNumber {0} , CustomerName {1}, JobDescription {2}, EstimatedHours {3}, JobPrice {4} ",
JobNumber, CustomerName, JobDescription, EstimatedHours, JobPrice);
}
}
//Part 3c solution
class RushJob : Job, IComparable // IComparable for comparing the objects
{
public RushJob(int jobNumber, string customerName, string jobDescription, int extimatedHours)
: base(jobNumber, customerName, jobDescription, extimatedHours)
{
JobPrice = 150 + JobPrice;
}
public int CompareTo(object obj)
{
RushJob rushJob = obj as RushJob;
if (rushJob.JobNumber < JobNumber)
{
return 1;
}
if (rushJob.JobNumber > JobNumber)
{
return -1;
}
// The orders are equivalent.
return 0;
}
}
class Program
{
static void Main(string[] args)
{
// 3a Solution
Object job1 = new Job(121, "Robert", "Repair service for Robert", 2);
Object job2 = new Job(121, "Joy", "Repair service for Joy", 3);
if (job1.Equals(job2))
{
Console.WriteLine("Result from Equals = Same objects");
}
else
{
Console.WriteLine("Result from Equals = Different objects");
}
if (job1.GetHashCode() == job2.GetHashCode())
{
Console.WriteLine("Result from GetHashCode = Same ");
}
else
{
Console.WriteLine("Result from GetHashCode = Different ");
}
Console.WriteLine("To string result job1 object = {0}", job1.ToString());
Console.WriteLine("To string result job2 object = {0}", job2.ToString());
////3b Solution
Job[] jobArray = new Job[5];
int i = 0;
while (true)
{
Console.WriteLine("Enter the {0} user data", i + 1);
Console.WriteLine("Enter the Job Number");
int jobNumber = Convert.ToInt32(Console.ReadLine());
if (i > 0)
{
bool jobNumberFound = false;
for (int j = 0; j < i; j++)
{
if (jobArray[j].JobNumber == jobNumber)
{
jobNumberFound = true;
Console.WriteLine("Job Number is already entered.. enter it again");
break;
}
}
if (jobNumberFound)
{
continue;
}
}
Console.WriteLine("Enter the Customer Name");
string customerName = Console.ReadLine();
Console.WriteLine("Enter the Job Description");
string jobDescription = Console.ReadLine();
Console.WriteLine("Enter the Estimated hours");
int extimatedHours = Convert.ToInt32(Console.ReadLine());
jobArray[i] = new Job(jobNumber, customerName, jobDescription, extimatedHours);
i++;
if (i == 5)
{
break;
}
}
Console.WriteLine("======Entered Data For Rush Job ===========");
int totalPrice = 0;
for (int k = 0; k < 5; k++)
{
Console.WriteLine(jobArray[k].ToString());
totalPrice = totalPrice + jobArray[k].JobPrice;
}
Console.WriteLine("Total Price = {0}", totalPrice);
//3c Soluction
Job[] rushJobArray = new RushJob[5];
List<Job> rushJobList = new List<Job>(); // This is for 3d solution
int counter = 0;
while (true)
{
Console.WriteLine("Enter the {0} user data", counter + 1);
Console.WriteLine("Enter the Job Number");
int jobNumber = Convert.ToInt32(Console.ReadLine());
if (counter > 0)
{
bool jobNumberFound = false;
for (int j = 0; j < counter; j++)
{
if (rushJobArray[j].JobNumber == jobNumber)
{
jobNumberFound = true;
Console.WriteLine("Job Number is already entered.. enter it again");
break;
}
}
if (jobNumberFound)
{
continue;
}
}
Console.WriteLine("Enter the Customer Name");
string customerName = Console.ReadLine();
Console.WriteLine("Enter the Job Description");
string jobDescription = Console.ReadLine();
Console.WriteLine("Enter the Estimated hours");
int extimatedHours = Convert.ToInt32(Console.ReadLine());
rushJobArray[counter] = new RushJob(jobNumber, customerName, jobDescription, extimatedHours);
rushJobList.Add(rushJobArray[counter]);
counter++;
if (counter == 5)
{
break;
}
}
Console.WriteLine("======Entered Data ===========");
int totalPriceRushJob = 0;
for (int k = 0; k < 5; k++)
{
Console.WriteLine(rushJobArray[k].ToString());
totalPriceRushJob = totalPriceRushJob + rushJobArray[k].JobPrice;
}
Console.WriteLine("Total Price = {0}", totalPriceRushJob);
Console.WriteLine("Sorting the entered data based on job number");
rushJobList.Sort();
Console.WriteLine("Printing the sorted data");
foreach (Job j in rushJobList)
{
Console.WriteLine(j.ToString());
}
}
}
}
//PLEASE PROVIDE FEEDBACK THUMBS UP