473,768 Members | 7,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shared members, Collections, Events Problem?

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 Light
class? 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.


--
- WJ.
--
Wujood
Mar 23 '07 #1
2 963
by the way im understanding it, you could just create a Light object that has
a property On (boolean) and brightness (integer 0-100). Then create a Scene
class that has a list of all lights inside of it (plus an on or off
property). hopefully this gives u a slight push in the right direction
--
-iwdu15
Mar 23 '07 #2
Well, so far I have following:

public class Light
{
private string lightId;
private ArrayList scenes;
private bool lightState;

public Light()
{
//init values here
}

//some properties and methods
}
....Then I also have a derived class >>public class AdjustableLight : Light
...... that has a property to set the light level.

public class Scene
{
private string sceneId;
private bool sceneState; //true = ON, false = OFF
private ArrayList lights;

public Scene(string id)
{
sceneId = id;
sceneState = false;
lights = new ArrayList( );
}

//Some methods and props here

}

The problem is how to make sure Light 3 stays ON after Scene B is turned
off? Do I also need to use events here??
"iwdu15" wrote:
by the way im understanding it, you could just create a Light object that has
a property On (boolean) and brightness (integer 0-100). Then create a Scene
class that has a list of all lights inside of it (plus an on or off
property). hopefully this gives u a slight push in the right direction
--
-iwdu15
Mar 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3567
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base class *Shared* methods which make use of the class ID. So I gave the base class a classID field, and then I gave the derived classes Shared constructors, which I used to set the classID field to the appropriate values for each derived class. But...
1
1643
by: Iulian Ionescu | last post by:
I have the following problem. I derived a class from ArrayList to provide some additional events I need. Then I derived 2 different classes from this one and each of them defines an indexer that returns the specified object. For example, the list for Group types will have: public new Group this { get {return (Group)base;}
3
2038
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When DataNode is changed, it raises "Changed" event. The class has a reference to the DataNode it is being contained in: - DataTree - tree like data structure that contains DataNodes; When
3
5796
by: Ryan Steckler | last post by:
I found this behavior while trying to implement a singleton class. Below is a somewhat more straight forward example, though admittedly less useful in real life. The basic problem is that when a static property of a class is called (StaticInit.MyProperty), the property code executes BEFORE the static members are initialized. This would lead one to assume that the static members would equate to null, but that isn't the case either. They...
11
2255
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe." I have 2 questions: 1. I thought dynamic variables are thread-safe since threads have their own
6
1780
by: Daniel Fernandes | last post by:
Hi there Is there any difference I need to be aware when I create a class with only shared members & procedures when compared to a module (which is a shared class) ? I am asking this because I have seen at work a class that declares a Database connection as a shared member and I wonder if that's a very bad programming practice..
4
3362
by: Rubbrecht Philippe | last post by:
Hi there, I would like to develop an interface that when implemented in a class requires a number of shared properties or methods to be available. It seems a Shared Member can not be used as interface member implementation?! Is there a workaround to this problem?! Best regards, Philippe Rubbrecht
5
1577
by: Simon | last post by:
Hi all, We have an ASP.NET 1.1 application running on IIS6 on Server 2003. Most of the base objects we are using in this application are taken from a windows application also written by us. We have used shared properties on some of these objects to enable caching of frequently used objects, so save fetching them from SQL every time. These shared properties vastly increase performance of our windows app.
2
1881
by: =?Utf-8?B?V3Vqb29k?= | last post by:
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...
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10175
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9961
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8840
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5283
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.