Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. i want to solve this

i want to solve this

Scheduled Pinned Locked Moved C#
helptutorial
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nabawoka
    wrote on last edited by
    #1

    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

    L N E 3 Replies Last reply
    0
    • N Nabawoka

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 your Result() method should return the sum, product, difference etc as appropriate.

      I must get a clever new signature for 2011.

      N 1 Reply Last reply
      0
      • L Lost User

        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 your Result() method should return the sum, product, difference etc as appropriate.

        I must get a clever new signature for 2011.

        N Offline
        N Offline
        Nabawoka
        wrote on last edited by
        #3

        i konw but i can't do the implementation of second interface interface IThingManager :(

        1 Reply Last reply
        0
        • N Nabawoka

          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

          N Offline
          N Offline
          Nabawoka
          wrote on last edited by
          #4

          please i want the implementation of IThingManager Please :)

          E 1 Reply Last reply
          0
          • N Nabawoka

            please i want the implementation of IThingManager Please :)

            E Offline
            E Offline
            Estys
            wrote on last edited by
            #5

            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

            N D 2 Replies Last reply
            0
            • N Nabawoka

              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

              E Offline
              E Offline
              Estys
              wrote on last edited by
              #6

              See my answer above. Cheers

              If you can read this, you don't have Papyrus installed

              1 Reply Last reply
              0
              • E Estys

                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

                N Offline
                N Offline
                Nabawoka
                wrote on last edited by
                #7

                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

                E 1 Reply Last reply
                0
                • N Nabawoka

                  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

                  E Offline
                  E Offline
                  Estys
                  wrote on last edited by
                  #8

                  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

                  OriginalGriffO 1 Reply Last reply
                  0
                  • E Estys

                    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

                    OriginalGriffO Online
                    OriginalGriffO Online
                    OriginalGriff
                    wrote on last edited by
                    #9

                    :thumbsup:

                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    • E Estys

                      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

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      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

                      E 1 Reply Last reply
                      0
                      • D 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

                        E Offline
                        E Offline
                        Estys
                        wrote on last edited by
                        #11

                        You're just being flippant :)

                        If you can read this, you don't have Papyrus installed

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups