Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Repair In this exercise, you will continue creating the Auto Repair system you designed a part of in the previous exercise. This time we will
Repair In this exercise, you will continue creating the Auto Repair system you designed a part of in the previous exercise. This time we will turn our attention to programming a part of the system - namely the Repair class. Here's the class diagram to use for this: - repair Date: Date Time - description: string - supplies: string - numberOfMinutes: int -hourlyRate: double - amountPaid: double You're expected to practice pair programming by working side-by-side on a single computer and taking turns with who is driving and who is navigating' + AddSupplies(supplies: string) + AddTime(minutes: int) + Pay(amount: double) + Is Paid: boolean Adding Fields and Properties Start a new C# Console App project in Visual Studio (New Project -> Templates -> Visual C#> Windows Classic Desktop -> Console App). Add a new class to the project named Repair. Start by creating properties for the first three fields (repairDate. description and supplies). Properties are public, so they start with upper-case letters. These fields can be changed directly from the outside with no problems, so they're ok as properties. You can implement the fields as automatic properties on this pattern: public string Description { get; set; } This creates a public property called Description of type string that can be read and updated directly. The next fields (numberOfMinutes, and hourlyRate, and amountPaid) are a little different. We imagine a system where a technician could add time worked on a repair on multiple occasions, and a customer might similarly pay a partial amount of the payment. So, we don't just want to allow for changing the total number of minutes worked and the amount paid directly. Instead, we want to force clients of this class to go through the methods. At some point in the future we might also want to expand the system to record the individual transactions of payment and adding time. To accomplish this, add private fields for numberOfMinutes, hourly Rate, and amountpaid. Make sure they're marked as private. We kept the three fields private so they could only be changed through methods, but it would be OK to be able to read their values. This can be done by adding a read-only property for each field. Here's the code for the first one: public int NumberOfMinutes { get { return numberOfMinutes; } } Exercise: Add read-only properties for the remaining fields. Testing Before moving on, let's make sure we can create Repair objects and interact with them in simple ways. Open the Program.ss file and add code in the Main method to create a Repair object: class Program O references static void Main(string[] args) Repair repair1 = new Repair(); repair1. Description = "Oil Change"; repair1. RepairDate = DateTime. Today; //today's date repair1. Supplies - "5 quarts of oil, oil filter"; Console.WriteLine("Repair date: {0}, Description: {1}, Supplies: {2}", repair1. RepairDate.ToShortDateString(), repair1.Description, repair1. Supplies); Console.ReadKey(); Run the code and check that the output looks as expected. Here's what I got: file:///C:/Users/iverser/Desktop/S 318-515/AutoRepair/Auto Repair/bin/Debug/Auto Repair.EXE 26 Repair date: 1/22/2015. Description: Oil Change, Supplies: 5 quarts of oil, oil. filter Exercise: Add a constructor to the Repair class to take a description, a date, and a string with the supplies. The constructor should also set the hourly rate to $55. Rewrite the code in the Main method to use the constructor and check that the output looks like before. Exercise: Create additional Repair objects in the Main method with dates that are different from today's date and values that are different from those in repair1. Methods Now that you can create objects and store data, you will need to add more of the functionality that the design calls for. Start by adding the AddTime method. This is a method that should take a mumber of minutes that a technician worked on a repair and then increase the numberOfMinutes, field. Here's what the signature of the method looks like - notice that it is public, doesn't return anything (void), and takes a single integer (minutes) as a parameter: public void AddTime(int minutes) Exercise: Add the functionality to increase the number of minutes for the repair. Exercise: Add the remaining methods in the class diagram by writing the code directly in Repain.es. The class diagram should end up looking as shown here. For AddSupplies, you can append the string to the existing list of supplies. For the Pay method, you should check to make sure the amount is positive. The IsPaid method will likely prove to be the most difficult. You will need to use the information available in the class to determine if the repair bill has been paid in full, and then return true. Return false if there is an outstanding balance. Testing To test your repair class, change the code in the Program.ss class to manipulate a Repair object: repair1. AddSupplies ("PCV Valve"); repairi. AddTime(35); repairi. AddTime (25); repairi. Pay(55); Console.WriteLine("Total Time: {0}", repairi. NumberOfMinutes); Console.WriteLine("Supplies: {@}", repairi. Supplies); Console.WriteLine("Total Amount: {0:c)", repair1. HourlyRate * repair1. NumberOfMinutes / 60.0); Console.WriteLine("Paid in full? {0}", repairi. Ispaid) ? "Yes" : "No"); Manipulate the test data until you're satisfied you have fully tested the code. Try to see if your code behaves well if you pay more than is owed on a repair, and if you try to add negative numbers for minutes and amount paid. Exercise: Format the total amount as currency. Exercise: Add a method to Repair to calculate the total amount of the Repair, then call that method from the Main method instead of calculating it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started