Shared members, Events, Collections problem?

G

Guest

I am trying to solve the following take home assignment problem. I am not
sure whether to use Hashtables, events and shared members or could it be done
more easily? Also, do I need to implement a Generic Collection for Lights?
Any help in terms of pseudo code or implementation would be appreciated.

----------------

Define a set of classes and methods to model these entities:
- a Light that you can turn on and off
- a Light that you can turn on and off and also set to a specific light
level e.g. 50% brightness.
- a Scene which contains a number of Lights, with a level specified for each
Light
o a Scene can be turned on or off
o Lights can be in multiple Scenes
o A Light is only turned off if all Scenes that it is part of are off

In our scenario we have 2 Scenes (A and B).
Scene A
- Lights 1 (on), 2 (on), and 3 (50%).

Scene B
- Lights 3 (70%), 4 (on), and 5 (on)

Write some client code that will create the objects to model our 2 Scenes,
turn on both scenes, then turn off Scene B. Please show the implementation
that will allow Light 3 to stay on after Scene B is turned off.
 
J

Jon Skeet [C# MVP]

Wujood said:
I am trying to solve the following take home assignment problem. I am not
sure whether to use Hashtables, events and shared members or could it be done
more easily? Also, do I need to implement a Generic Collection for Lights?
Any help in terms of pseudo code or implementation would be appreciated.

I don't see any requirement which would involve hashtables or events.
Not sure what you mean by "shared members".

I'd make the scene have a list of lights, but exactly what form that
would take depends on whether you're using .NET 1.1 or 2.0.
 
G

Guest

OK, I figured it out and it works. I realized the many to many relationship
between Light and Scene. So I use ArrayList for each in these two classes. I
know this could be made elegant using Generics in 2.0 but for the sake of
simplicity I use ArrayLists.

Thanks All.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top