i want to solve this
-
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();
}
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:
//1 For each group, output the name of that group, and a list of all members of that group.
//2 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
Please Help me i made the classes of adderthing & MultiplierThing that inherits from interface IThing and stop
You just need to implement the interface methods as you have defined them. Thus in each class your
Initialize()
method should store your variables (this could be done in a base class) and yourResult()
method should return the sum, product, difference etc as appropriate.I must get a clever new signature for 2011.
-
You just need to implement the interface methods as you have defined them. Thus in each class your
Initialize()
method should store your variables (this could be done in a base class) and yourResult()
method should return the sum, product, difference etc as appropriate.I must get a clever new signature for 2011.
-
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();
}
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:
//1 For each group, output the name of that group, and a list of all members of that group.
//2 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
Please Help me i made the classes of adderthing & MultiplierThing that inherits from interface IThing and stop
-
I'll give you a partial implementation. Since it's you homework, do the rest yourself.
public class ThingManager : IThingManager { Dictionary\> things = new Dictionary\>(); public void AddThing(string groupName, IThing thingToAdd) { if (!things.ContainsKey(groupName)) { things.Add(groupName, new List()); } things\[groupName\].Add(thingToAdd); // Remember that things\[groupName\] returns a List !! } }
Cheers
If you can read this, you don't have Papyrus installed
-
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();
}
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:
//1 For each group, output the name of that group, and a list of all members of that group.
//2 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
Please Help me i made the classes of adderthing & MultiplierThing that inherits from interface IThing and stop
-
I'll give you a partial implementation. Since it's you homework, do the rest yourself.
public class ThingManager : IThingManager { Dictionary\> things = new Dictionary\>(); public void AddThing(string groupName, IThing thingToAdd) { if (!things.ContainsKey(groupName)) { things.Add(groupName, new List()); } things\[groupName\].Add(thingToAdd); // Remember that things\[groupName\] returns a List !! } }
Cheers
If you can read this, you don't have Papyrus installed
-
thaaaaanx alot Estys :D:D but i can't complete because i didn`t deal with collections before and don`t know how to implement the method sum how to add items in gruopname and how to read from user to add in groupname :) sorry
Collections are dead easy :) The example I gave you already adds things to your group. To iterate over a collection use foreach :
public int Sum(string groupName) { int retValue = 0; foreach (IThing ithing in things\[groupName\]) { retValue += ithing.Result; } return retValue; }
You can do the same for TotalSum. The only difference is to iterate over the things groupNames with KeyValues Cheers
If you can read this, you don't have Papyrus installed
-
Collections are dead easy :) The example I gave you already adds things to your group. To iterate over a collection use foreach :
public int Sum(string groupName) { int retValue = 0; foreach (IThing ithing in things\[groupName\]) { retValue += ithing.Result; } return retValue; }
You can do the same for TotalSum. The only difference is to iterate over the things groupNames with KeyValues Cheers
If you can read this, you don't have Papyrus installed
:thumbsup:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
I'll give you a partial implementation. Since it's you homework, do the rest yourself.
public class ThingManager : IThingManager { Dictionary\> things = new Dictionary\>(); public void AddThing(string groupName, IThing thingToAdd) { if (!things.ContainsKey(groupName)) { things.Add(groupName, new List()); } things\[groupName\].Add(thingToAdd); // Remember that things\[groupName\] returns a List !! } }
Cheers
If you can read this, you don't have Papyrus installed
Estys wrote:
If you can read this, you don't have Papyrus installed
I DO have Papyrus installed and can still read it. Now what?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Estys wrote:
If you can read this, you don't have Papyrus installed
I DO have Papyrus installed and can still read it. Now what?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak