Question: Adding Fields and Properties Start a new C# Console App project in Visual Studio (New Project -> Templates -> Visual C#> Windows Classic Desktop ->

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 theyre ok as properties. You can implement the fields as automatic properties on this pattern:

Adding Fields and Properties Start a new C# Console App project in

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 dont 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, hourlyRate, and amountPaid. Make sure theyre marked as private.

Testing

Before moving on, lets make sure we can create Repair objects and interact with them in simple ways. Open the Program.cs file and add code in the Main method to create a Repar Object:

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.

Exercise: Create additional Repair objects in the Main method with dates that are different from todays date and values that are different from those in repair1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!