none
Class Related questions

    Question

  • Hello,

    I have been asked below questions in my final exam of school. It's little hard to understand this. would like ti know if someone gives me a sample for each scenario in this. it will help me to understand further.

    Write a program in C#/.NET that contains the following:
    An enumerated type, representing the possible resource types in the program, containing the following values: Hardware, Firmware, Software, and Other.
    
    A class, entitled Resource, that contains two pieces of data. The first is an instance of the enumerated type above. The second is an integer that represents the number of units of the enumerated type specified in the first piece of data. The class should have a constructor or member function that accepts the enumerated type and the value of the units variable.
    
    A class, entitled Requirements, that contains two pieces of data. The first is an instance of the enumerated type above. The second is an integer that represents the required number of units of the enumerated type specified in the first piece of data. The class should have a constructor or member function that accepts the enumerated type and the value of the units variable.
    
    A class, entitled Provider, which contains a collection of zero to four instances of the Resource class. The class should have member functions that allows for addition and removal of Resources. No instance of the Resource class that is added to the Provider should be able to have the same value of the enumerated type as another instance currently present in the Provider.
    
    A class, entitled, Demands, which contains a collection of zero to four instances of the Requirements class. The class should have member functions that allow for addition and removal of Requirements. No instance of the Requirements class that is added to the Demands should be able to have the same value of the enumerated type as another instance currently present in the Demands.
    
    A method which takes an instance of a Provider, and an instance of a Demands, and returns how many whole multiples of the set of Requirements inside the Demands instance are present in the set of Resources inside the Provider instance.
    One or more test methods which:
    
    Create an instance of a Provider with different numbers and combinations of Resources;
    Create an instance of a Demands with different numbers and combinations of Requirements;
    Invoke the previous method using the Provider and Demands from (1) and (2) above;
    Verify that the value returned from the method is correct.
    


    loving dotnet

    Wednesday, May 22, 2019 7:13 PM

Answers

  • Please note that Jack's code does not actually fix any of the problems in your original code.  I'm not sure what he was trying to demonstrate, but he apparently didn't read your original specs.

    Think about working through some concrete examples on paper.  That might give you some help.  Let's say you have 18 hardware resources, 9 software resources, and 15 firmware resources.  That would be a Provider containing 3 Resource instances.  You ought to be able to write code to add those, once you fix AddResource.

    Now imagine you have a need for 3 hardware resources, 3 software resources, and 4 firmware resources.  That would be a Demands object containing 3 separate Requirements objects.

    Now, think about the "method" you are asked to write.  What that method is going to determine is that you could satisfy 6 hardware demands (18 / 3), and 3 software demands (9 / 3) and 3 firmware demands (15 / 4).  The question asks for how many "whole multiples" there are, and that would be the smallest number, which is 3.  Your Provider has 3 complete copies of the set of Demands.

    If you actually took this class, then I'm sure this kind of thing was covered.  If you didn't take the class, then I guess you will fail the test.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by Born2Achieve Monday, May 27, 2019 12:46 AM
    Thursday, May 23, 2019 5:59 PM

All replies

  • Hello,

    Were you not taught how to write againsts these requirements? If so you should have asked for assistance from whomever taught the class before the final exam as this as I'm guessing going to be a real struggle and we are not here to teach you. You need to work with each task, write code and when stuck come back here and ask for assistance with one specific part of the task. Get that done, start a brand new question next time there is a issue.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, May 22, 2019 8:03 PM
    Moderator
  • The requirements seems very straightforward.

    Better you post your attempt and let people help you out rather than getting someone to do your homework for you ?

    Andy

    Wednesday, May 22, 2019 9:10 PM
  • Hello Guys,

    Thank you for the reply and i would like to give try with step by step. i would request to help me to achieve with my try. here is my try for class declarations for below

    A class, entitled Resource, that contains two pieces of data. The first is an instance of the enumerated type above. The second is an integer that represents the number of units of the enumerated type specified in the first piece of data. The class should have a constructor or member function that accepts the enumerated type and the value of the units variable.
    
    A class, entitled Requirements, that contains two pieces of data. The first is an instance of the enumerated type above. The second is an integer that represents the required number of units of the enumerated type specified in the first piece of data. The class should have a constructor or member function that accepts the enumerated type and the value of the units variable.
    
    A class, entitled Provider, which contains a collection of zero to four instances of the Resource class. The class should have member functions that allows for addition and removal of Resources. No instance of the Resource class that is added to the Provider should be able to have the same value of the enumerated type as another instance currently present in the Provider.
    
    A class, entitled, Demands, which contains a collection of zero to four instances of the Requirements class. The class should have member functions that allow for addition and removal of Requirements. No instance of the Requirements class that is added to the Demands should be able to have the same value of the enumerated type as another instance currently present in the Demands.
    

    Code :

    using System;
    using System.Collections.Generic;
    
    namespace Test.ClassFiles
    {
        internal class AllClass
        {
        }
    
        public enum ResourceType
        {
            Hardware = 1,
            Firmware = 2,
            Software = 3,
            Other = 4
        }
    
        public class Resource
        {
            ResourceType resourceType = 0;
            int NoOfUnits = Enum.GetNames(typeof(Resource)).Length;
            public Resource(ResourceType enuResourceType,int unit)
            {
    
            }
    
        }
        public class Requirements
        {
            ResourceType resourceType = 0;
            int NoOfUnits = Enum.GetNames(typeof(Resource)).Length;
            public Requirements(ResourceType enuResourceType, int unit)
            {
    
            }
    
        }
        public class Provider
        {
            public List<Resource> lstInstance = new List<Resource>();
            public List<Resource> AddResource(List<Resource> lstRresources)
            {
                ResourceType resourceType = new ResourceType();
    
                   Resource resource = new Resource(resourceType,0);
                lstRresources.Add(resource);
                return lstRresources;
    
            }
        }
    
        public class Demands
        {
            public List<Requirements> lstInstance = new List<Requirements>();
            public List<Requirements> AddResource(List<Requirements> lstRresources)
            {
                ResourceType resourceType = new ResourceType();
    
                Requirements resource = new Requirements(resourceType, 0);
                lstRresources.Add(resource);
                return lstRresources;
    
            }
        }
    }

    Please help to verify this code for the portion i mentioned above and help me to correct if something wrong.

     

    loving dotnet

    Thursday, May 23, 2019 1:36 AM
  • This is a start.  You do not need to provide default values for your fields, since they all have constructors.  However, your constructors are not initializing any of the fields.  Your AddResource functions should not accept a list, they should accept a single Resource or Requirements object, and add it to the appropriate list.  Remember that you have to check for duplicated before adding to the list.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Thursday, May 23, 2019 7:16 AM
  • Hi Born2Achieve,

    Thank you for posting here.

    For your question, you want to achieve the correct code from your current result.

    You could refer to the following code.

    public class Resource
            {
               public ResourceType resourceType = new ResourceType();
               public int NoOfUnits = Enum.GetNames(typeof(ResourceType)).Length;
                public Resource(ResourceType enuResourceType, int unit)
                {
    
                }
                public Resource()
                {
    
                }
            }
            public class Requirements
            {
               public ResourceType resourceType = new ResourceType();
               public int NoOfUnits = Enum.GetNames(typeof(ResourceType)).Length;
                public Requirements(ResourceType enuResourceType, int unit)
                {
    
                }
                public Requirements()
                {
    
                }
    
            }
            public class Provider
            {
                public List<Resource> lstInstance = new List<Resource>();
                public List<Resource> AddResource(List<Resource> lstRresources)
                {
                    int count = 1;
                    foreach (ResourceType item in Enum.GetValues(typeof(ResourceType)))
                    {
                        Resource resource = new Resource(item, count);
                        lstRresources.Add(resource);
                        count++;
                    }
                    return lstRresources;
                }
    
                public List<Resource> DeleteResource(ResourceType resourceType,int m)
                {
                    Resource resource = new Resource(resourceType, m);
                    lstInstance.Remove(resource);
                    return lstInstance;
                }
            }
    
            public class Demands
            {
                public List<Requirements> lst = new List<Requirements>();
                public List<Requirements> AddResource(List<Requirements> lstRresources)
                {
                    int count = 1;
                    foreach (ResourceType item in Enum.GetValues(typeof(ResourceType)))
                    {
                        Requirements requirements = new Requirements(item, count);
                        lstRresources.Add(requirements);
                        count++;
                    }
                    return lstRresources;
    
                }
                public List<Requirements> DeleteResource(ResourceType resourceType, int m)
                {
                    Requirements requirements = new Requirements(resourceType, m);
                    lst.Remove(requirements);
                    return lst;
                }
            }

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, May 23, 2019 8:22 AM
  • Hi Jack,

    Thanks a lot and from my first thread i mentioned the full requirement. i am struggling with two of them here.

    along with the code correction from you, below things needs to be written

    A method which takes an instance of a Provider, and an instance of a Demands, and returns how many whole multiples of the set of Requirements inside the Demands instance are present in the set of Resources inside the Provider instance.
    
    Create an instance of a Provider with different numbers and combinations of Resources;
    Create an instance of a Demands with different numbers and combinations of Requirements;
    Invoke the previous method using the Provider and Demands from (1) and (2) above;
    Verify that the value returned from the method is correct.
    

    on the demand calls need to create a method 

    public void CheckMultiples(Provider provider,Demands demands)
            {
                /*A method which takes an instance of a Provider, and an instance of a Demands, and returns how many whole multiples of the set of Requirements inside the Demands instance are present in the set of Resources inside the Provider instance. */
            }

    and needs to create test methods for the below

    Create an instance of a Provider with different numbers and combinations of Resources;
    Create an instance of a Demands with different numbers and combinations of Requirements;
    Invoke the previous method using the Provider and Demands from (1) and (2) above;
    Verify that the value returned from the method is correct.
    
    This is highly out of my knowledge and i would request to help me in this by giving sample. it would help me to understand and learn with the sample.


    loving dotnet

    Thursday, May 23, 2019 4:08 PM
  • What part is "out of your knowledge"?  Keep in mind that you are asking for help with your final exam assignment. We should not be posting any complete code samples for you (maybe a snippet or two), but rather explain in words (as @Tim did) what you can change in the code sample that *you* provided us and clarify where you're not doing something correctly.

    So, try something (to the best of your knowledge) and then run it by us for critique.


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, May 23, 2019 4:30 PM
    Moderator
  • Please note that Jack's code does not actually fix any of the problems in your original code.  I'm not sure what he was trying to demonstrate, but he apparently didn't read your original specs.

    Think about working through some concrete examples on paper.  That might give you some help.  Let's say you have 18 hardware resources, 9 software resources, and 15 firmware resources.  That would be a Provider containing 3 Resource instances.  You ought to be able to write code to add those, once you fix AddResource.

    Now imagine you have a need for 3 hardware resources, 3 software resources, and 4 firmware resources.  That would be a Demands object containing 3 separate Requirements objects.

    Now, think about the "method" you are asked to write.  What that method is going to determine is that you could satisfy 6 hardware demands (18 / 3), and 3 software demands (9 / 3) and 3 firmware demands (15 / 4).  The question asks for how many "whole multiples" there are, and that would be the smallest number, which is 3.  Your Provider has 3 complete copies of the set of Demands.

    If you actually took this class, then I'm sure this kind of thing was covered.  If you didn't take the class, then I guess you will fail the test.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    • Marked as answer by Born2Achieve Monday, May 27, 2019 12:46 AM
    Thursday, May 23, 2019 5:59 PM
  • thanks a lot guys and i will take your advice. appreciated the time on this.

    loving dotnet

    Monday, May 27, 2019 12:46 AM