In this exercise I will ask you to create two classes to hold data from user input. We will use the console to retrieve our data by asking the user to create the object.
1. Create a Console application;
2. Create a class named Client;
3. Add the following properties to your Client class : FirstName, LastName, Email, Address, PhoneNumber;
4. Create a parameter and a default constructor for the client class.
5. Create a class named Validator;
6. Create 3 methods in your validation with the following signatures: bool ValidateIfEmptyField(string Text), bool ValidateEmail(string Email), bool ValidatePhoneNumber(string PhoneNumber).
7. With a little bit of research, you can even set the Validator class to static.
In the program.vb/program.cs class, you need to ask the user for the information to create a client, then validate the entered information and finally create the client object by using the information provided.
The last thing you will want to do is to display the client in the console (you can implement the ToString() method if you want!). Remember what String concatenation was, it might help you.
Here is an example of the program output :
Please enter the client first name: Alexandre Please enter the client last name: Sauve Please enter his/her email: email@example.com Please enter his/her address: 56000 test rd. finally enter the phone number: 888888888 Client information: FirstName: Alexandre LastName: Sauve Email: firstname.lastname@example.org Address: 56000 test rd. PhoneNumber: 8888888888
Note: for the validation, you can do basic validation, like the phone number size (10), you don’t have to complicate things. But if you really want a challenge, you can try the regular expressions! Good luck!
I will provide the correction for this exercise tomorrow, then we’re going to do another exercise on classes but with Windows Forms this time!