Question: I am looking for a solution to Murachs C# 2015 Exercise 13-1. The problem is as follows : In this exercise, you will create a

I am looking for a solution to Murachs C# 2015 Exercise 13-1. The problem is as follows:

In this exercise, you will create a customer Maintenance application that uses classes with the features presented. To make this application easier to develop, you will be given the starting forms and classes to work with that you will modify.

Open the project and add validation code to the Customer class

Open the application in the C:\C# 2015\Chapter 13\ CustomerMaintenance directory.

Open the Customer class and note how the constructor for this class sets the properties to the appropriate parameters. Then, add code to the set accessors for the FirstName, LastName, and Email properties that throws an exception if the value is longer than 30 characters.

Test the class by trying to add a new customer with an email address that's longer than 30 characters. When you do, an exception should be thrown. Then, end the application.

Set the MaxLength properties of the First Name, Last Name, and Email text boxes to 30. Then, run the application again and try to add a new customer with an email address that's longer than 30 characters. This shows one way to avoid the exceptions, but your classes should still throw them in case they are used by other applications that don't avoid them.

Add a CustomerList class

Add a class named CustomerList to the project, and declare a private variable that can store a list of Customer objects.

Add the following members to the CustomerList class, coding Count as an expression-bodied property and Fill and Save as expression-bodied methods:

Constructor Description
() Creates a new list of Customer objects.
Indexer Description
[index] Provides access to the customer at the specified position.
Property Description
Count An integer that indicates how many Customer objects are in the list.
Method Description
Add(customer) Adds the specified Customer object to the list.
Remove(customer) Removes the specified Customer object from the list
Fill() Fills the list with customer data from a file using the GetCustomers method of the CustomerDB class.
Save() Saves the customers to a file using the SaveCustomers method of the CustomerDB class.

Modify the Customer Maintenance form to use this class. To do that, you will need to use the Fill and Save method of the CustomerList object instead of the mothods of the CustomerDB class. In addition, you will need to use a for loop instead of a foreach loop when you fill the list box.

Run the application and test it to be sure it works properly.

Add overloaded operators to the CustomerList class

Add overloaded + and - operators to the CustomerList class that add and remove a customer from the customer list.

Modify the Customer Maintenance form to use these operators instead of the Add and Remove methods. Then, run and test the application.

Add a delegate and an event to the CustomerList Class

Add a delegate named ChangeHandler to the CustomerList Class. This delegate should specify a method with a void return type and a CustomerList parameter as described in figure 13-5.

Add an event named Changed to the CustomerList class. This event should use the ChangeHandler delegate and should be raised any time the customer list changes as described in figure 13-6.

Modify the Customer Maintenance form to use the Changed event to save the customers and refresh the list box any time the list changes. To do that, you'll need to code an event handler that has the signature specified by the delegate, you'll need to wire the event handler to the event, and you'll need to remove any unnecessary code from the event handlers for the Save and delete buttons.

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!