Exercise: Create an interface to treat room hires and dates the same

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!

Category ==> Visual C Sharp 2010  (65 exercises)
Topic ==> Interfaces  (2 exercises)
Level ==> Average difficulty
Course ==> Adv C# | Classes & LINQ
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Create a new project called Advanced_CSharp_exercises.  Add the files in the folder above into a new project.

To do this, right-click on the project and choose Add --> Existing Item...  Be careful to add all of the files, not just the ones of certain type.

Set the frmMeetings form to be the default one for the project, then run the project - you should now see that it gives you a very short list of invitations to send:

Invitations to send

Each invitation has a description, an addresse and the text.

To start, have a quick look at the Venue, Customer, Tryst and RoomHire classes.

If you look at the code behind the form, you'll see that it also creates 3 venues, 3 customers, 2 trysts (dates between customers) and 2 room hires:

// create some venues

Venue RedLion = new Venue("Red Lion, High Street");

Venue CostaCoffee = new Venue("Costa Coffee, Market Street");

Venue CatholicChurch = new Venue(

"Church of Immaculate Conception, Church Road");

 

// create some people

Customer c1 = new Customer("Rita", "Brown");

Customer c2 = new Customer("Sue", "Jones");

Customer c3 = new Customer("Bob", "Smith");

 

// arrange some trysts between customers (Bob

// pessimistically meets 2 ladies)

Tryst t1 = new Tryst(c1, c3, RedLion,

new System.DateTime(2013, 11, 25, 11, 30, 0));

Tryst t2 = new Tryst(c2, c3, CostaCoffee,

new System.DateTime(2013, 11, 25, 12, 0, 0));

 

// now add separate room hires for speed

// dating (2 running simultaneously,

// although the Catholic Church one doesn't last as long)

DateTime whenStart = new System.DateTime(2013, 11, 22, 10, 0, 0);

RoomHire rh1 = new RoomHire(CostaCoffee,

whenStart, whenStart.AddHours(2));

RoomHire rh2 = new RoomHire(CatholicChurch,

whenStart, whenStart.AddHours(1));

Some code has been commented out:

// now create some happenings!

// List happenings = new List{I_Happening>();

// happenings.Add(t1);

// happenings.Add(t2);

// happenings.Add(rh1);

// happenings.Add(rh2);

Your task is to add an interface called I_Happening which includes the following member:

// a happening must support a list of invitations

List Requests { get; }

You'll need to amend the Tryst and RoomHire classes to implement this interface, and get them to support the required property.

Uncomment the code which is commented out.  Add code to add one row to the data table for each request for each happening!

Run your program - you should get something like this:

Final list of invitations

Notice how each tryst has added two invitations: one for each person.

Close down any open files!

This page has 0 threads Add post