Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Some line of codes

    Create a class named Service. Inside the Service class, declare a class variable named Started. The datatype of this variable is Boolean.

    Code:
    Public Class Service
    Dim started as Boolean 
    End Class
    Create a class named Server. Inside the Server class, declare a dynamic array that can contain elements of the type Service.(Note: For convenience, both the array and the variable Started can be accessible from a client program
    that creates an instance of Server and Service respectively)

    Create a constructor for the Service class. When the constructor is executed, it will set the value of the class variable Started to True.

    Create two new classes: WebServer and DatabaseEngine. Both of these classes inherit from the class Service.

    Inside the Service class, declare a Sub procedure (method) named Terminate. This method should display
    the following text “Service stopping…” in a message box when executed. This method can be overridden in classes that inherit from Service class.

    Inside both the WebServer and DatabaseEngine class, override the method Terminate inherited from their base class Service. Both methods should first call the base class Terminate method. The messages “Web server stopping…” and “Database engine stopping…” should also be displayed in a message box when the Terminate method for the WebServer and DatabaseEngine are called respectively. These messages should only be displayed if the Started variable inherited from their base class is not equal to False.

    Inside the Server class, declare a method named Shutdown. This method does not return any value. When executed, it will call the Terminate method for each of the Service instances (if any) in the arrServices
    array. You should call the Terminate method within a For Each loop that loops through the elements of the arrServices array.

    In the Sub Main method, create an instance of the class Server. Set the size of the arrServices array in
    your Server instance to contain 2 elements. Create first a WebServer instance and then a DatabaseEngine
    instance into this array. Call the Shutdown method from your Server instance.

    I could have done only a lil part. Can you guys help me with the rest? please?

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,662
    Thanks
    41
    Thanked 189 Times in 188 Posts
    Code:
    class example
        {
            static void Main(string[] args)
            {
                s[] _s = new s[2] { new ws(), new de()};
                
                foreach (s S in _s)
                {
                    S.Terminate();
                }
    
                Console.WriteLine("fin..");
                Console.ReadLine();
            }
        }
    Code:
    public class s
        {
            bool strt;
            //s[] sArray;
            List<s> sArray;
    
            public s()
            {
                strt = true;
            }
    
            public s(int i)
            {
                //sArray = new s[i];
                sArray = new List<s>(i);
            }
    
            public bool started
            {
                get
                {
                    return strt;
                }
                set
                {
                    strt = value;
                }
            }
    
            public virtual void Terminate()
            {
                Console.WriteLine("Terminating...");
            }
    
            public void shutdown()
            {
                this.started = false;
            }
        }
    Code:
     public class ws : s
        {
            public override void Terminate()
            {
                base.Terminate();
                if (base.started)
                {
                    Console.WriteLine("ws shutting down...");
                    base.shutdown();
                }
                else
                    Console.WriteLine("ws stopped...");
    
            } 
        }
    Code:
        public class de : s
        {
            public override void Terminate()
            {
                base.Terminate();
                if (base.started)
                {
                    Console.WriteLine("de stopping...");
                    base.shutdown();
                }
                else
                    Console.WriteLine("de stopped...");
            }
        }
    I would make an interface and leverage the generic list<> more (if you needed to go further with this)- You shouldn't be posting homework without doing anything- I'll leave it on you to translate

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •