// Simple class that computes a result from two values.
interface IThing {
// Set values from which Result is computed.
void Initialize(int value1, int value2);
int Result { get; }
}
// Contains IThings in named groups.
interface IThingManager {
// Add 'thingToAdd' to group named 'groupName'.
// Create new group 'groupName' if it doesn't exist.
void AddThing(string groupName, IThing thingToAdd);
// Compute sum of all IThings added to group 'groupName'.
int Sum(string groupName);
// Compute sum of all IThings added to all groups.
int TotalSum();
// Output text summary of the IThings contained in this IThingManager.
// (Text can be output using System.Console.WriteLine).
void Print();
}
i want to Write an implementation of the interfaces in these concrete classes:
// Result is the product of value1 and value2, as supplied in the
// ``Initialize`` method.
class MultiplierThing : IThing { ... }
// Result is the sum of value1 and value2.
class AdderThing : IThing { ... }
class ThingManager : IThingManager {
...
// Print: For each group, outputs the sum of the IThings in that group.
// Also output the total sum of all groups.
void Print() { ... }
}
Inherit VerboseThingManager from ThingManager, and change the functionality of the Print method to the following:
For each group, output the name of that group, and a list of all members of that group.
Also output the sums like the Print method of ThingManager
Example Ouput
Given a main program like this:
IThingManager manager = new VerboseThingManager();
IThing t;
t = new MultiplierThing();
t.Initialize(1, 2);
manager.AddThing("Group A", t);
t = new MultiplierThing();
t.Initialize(3, 4);
manager.AddThing("Group B", t);
t = new AdderThing();
t.Initialize(5, 6);
manager.AddThing("Group A", t);
t = new AdderThing();
t.Initialize(7, 8);
manager.AddThing("Group B", t);
manager.Print();
The corresponding output should be:
Group A:
- 2
- 11
Group B:
- 12
- 15
Sum of Group A = 13
Sum of Group B = 27
Total sum = 40
interface IThing {
// Set values from which Result is computed.
void Initialize(int value1, int value2);
int Result { get; }
}
// Contains IThings in named groups.
interface IThingManager {
// Add 'thingToAdd' to group named 'groupName'.
// Create new group 'groupName' if it doesn't exist.
void AddThing(string groupName, IThing thingToAdd);
// Compute sum of all IThings added to group 'groupName'.
int Sum(string groupName);
// Compute sum of all IThings added to all groups.
int TotalSum();
// Output text summary of the IThings contained in this IThingManager.
// (Text can be output using System.Console.WriteLine).
void Print();
}
i want to Write an implementation of the interfaces in these concrete classes:
// Result is the product of value1 and value2, as supplied in the
// ``Initialize`` method.
class MultiplierThing : IThing { ... }
// Result is the sum of value1 and value2.
class AdderThing : IThing { ... }
class ThingManager : IThingManager {
...
// Print: For each group, outputs the sum of the IThings in that group.
// Also output the total sum of all groups.
void Print() { ... }
}
Inherit VerboseThingManager from ThingManager, and change the functionality of the Print method to the following:
For each group, output the name of that group, and a list of all members of that group.
Also output the sums like the Print method of ThingManager
Example Ouput
Given a main program like this:
IThingManager manager = new VerboseThingManager();
IThing t; t = new MultiplierThing();
t.Initialize(1, 2);
manager.AddThing("Group A", t);
t = new MultiplierThing();
manager.AddThing("Group B", t);
t = new AdderThing();
t.Initialize(5, 6);
manager.AddThing("Group A", t);
t = new AdderThing();
t.Initialize(7, 8);
manager.AddThing("Group B", t);
manager.Print();
The corresponding output should be: Group A: - 2 - 11 Group B: - 12 - 15 Sum of Group A = 13 Sum of Group B = 27 Total sum = 40
So what's your problem? Do you not know how to add, how to multiply, how to implement an interface, how to send output to the console, or what? What code do you have so far?
harry_potter
0 Points
6 Posts
implementation of the interfaces
Jan 11, 2011 10:08 AM|LINK
Hello every one
Given these interfaces:
// Simple class that computes a result from two values.
interface IThing {
// Set values from which Result is computed.
void Initialize(int value1, int value2);
int Result { get; }
}
// Contains IThings in named groups.
interface IThingManager {
// Add 'thingToAdd' to group named 'groupName'.
// Create new group 'groupName' if it doesn't exist.
void AddThing(string groupName, IThing thingToAdd);
// Compute sum of all IThings added to group 'groupName'.
int Sum(string groupName);
// Compute sum of all IThings added to all groups.
int TotalSum();
// Output text summary of the IThings contained in this IThingManager.
// (Text can be output using System.Console.WriteLine).
void Print();
}
i want to Write an implementation of the interfaces in these concrete classes:
// Result is the product of value1 and value2, as supplied in the
// ``Initialize`` method.
class MultiplierThing : IThing { ... }
// Result is the sum of value1 and value2.
class AdderThing : IThing { ... }
class ThingManager : IThingManager {
...
// Print: For each group, outputs the sum of the IThings in that group.
// Also output the total sum of all groups.
void Print() { ... }
}
Inherit VerboseThingManager from ThingManager, and change the functionality of the Print method to the following:
For each group, output the name of that group, and a list of all members of that group.
Also output the sums like the Print method of ThingManager
Example Ouput
Given a main program like this:
IThingManager manager = new VerboseThingManager();
IThing t;
t = new MultiplierThing();
t.Initialize(1, 2);
manager.AddThing("Group A", t);
t = new MultiplierThing();
t.Initialize(3, 4);
manager.AddThing("Group B", t);
t = new AdderThing();
t.Initialize(5, 6);
manager.AddThing("Group A", t);
t = new AdderThing();
t.Initialize(7, 8);
manager.AddThing("Group B", t);
manager.Print();
The corresponding output should be:
Group A:
- 2
- 11
Group B:
- 12
- 15
Sum of Group A = 13
Sum of Group B = 27
Total sum = 40
Thanks
Mohamed Sayed
Yasser Shaik...
Participant
872 Points
251 Posts
Re: implementation of the interfaces
Jan 11, 2011 10:25 AM|LINK
please reformat your queestion, its difficult to read.
harry_potter
0 Points
6 Posts
Re: implementation of the interfaces
Jan 11, 2011 10:35 AM|LINK
sorry for this format i have reformated it now
Mohamed Sayed
Yasser Shaik...
Participant
872 Points
251 Posts
Re: implementation of the interfaces
Jan 11, 2011 10:42 AM|LINK
THIS IS HOW your Question should be written
interface IThing { // Set values from which Result is computed. void Initialize(int value1, int value2); int Result { get; } } // Contains IThings in named groups. interface IThingManager { // Add 'thingToAdd' to group named 'groupName'. // Create new group 'groupName' if it doesn't exist. void AddThing(string groupName, IThing thingToAdd); // Compute sum of all IThings added to group 'groupName'. int Sum(string groupName); // Compute sum of all IThings added to all groups. int TotalSum(); // Output text summary of the IThings contained in this IThingManager. // (Text can be output using System.Console.WriteLine). void Print(); }i want to Write an implementation of the interfaces in these concrete classes:
// Result is the product of value1 and value2, as supplied in the // ``Initialize`` method. class MultiplierThing : IThing { ... } // Result is the sum of value1 and value2. class AdderThing : IThing { ... } class ThingManager : IThingManager { ... // Print: For each group, outputs the sum of the IThings in that group. // Also output the total sum of all groups. void Print() { ... } }Inherit VerboseThingManager from ThingManager, and change the functionality of the Print method to the following: For each group, output the name of that group, and a list of all members of that group. Also output the sums like the Print method of ThingManager
Example Ouput Given a main program like this:
manager.AddThing("Group A", t); t = new MultiplierThing();manager.AddThing("Group B", t); t = new AdderThing(); t.Initialize(5, 6); manager.AddThing("Group A", t); t = new AdderThing(); t.Initialize(7, 8); manager.AddThing("Group B", t); manager.Print();The corresponding output should be: Group A: - 2 - 11 Group B: - 12 - 15 Sum of Group A = 13 Sum of Group B = 27 Total sum = 40
harry_potter
0 Points
6 Posts
Re: implementation of the interfaces
Jan 11, 2011 10:46 AM|LINK
mmmm i think i'm not looking for some one to tech me how to write a question , any way thnx
so if any body can help me guys
Mohamed Sayed
SGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: implementation of the interfaces
Jan 11, 2011 01:35 PM|LINK
Are you looking for someone to do your homework?
My blog
harry_potter
0 Points
6 Posts
Re: implementation of the interfaces
Jan 11, 2011 07:54 PM|LINK
no i'm not , it's a question was asked to me in an interview before but i did not know it
Mohamed Sayed
Paul Linton
Star
13431 Points
2535 Posts
Re: implementation of the interfaces
Jan 11, 2011 08:15 PM|LINK
So what's your problem? Do you not know how to add, how to multiply, how to implement an interface, how to send output to the console, or what? What code do you have so far?