Beispiel #1
0
        public static void ShowStatistics(MobileOperator mobileOperator)
        {
            MobileAccount[] subscribers = new MobileAccount[10];
            for (int i = 0; i < 10; i++)
            {
                subscribers[i] = new MobileAccount(mobileOperator);
            }

            GenerateRandomCalls(subscribers, 100);
            GenerateRandomSms(subscribers, 100);

            Console.WriteLine("\nTotal subscribers number: {0}", mobileOperator.SubscribersCount);

            Console.WriteLine("\n5 Most called: \n(number:\t calls)");
            SubscriberStats[] mostCalled = mobileOperator.GetMostCalledSubscribers(5);
            for (int i = 0; i < mostCalled.Length; i++)
            {
                Console.WriteLine("{0}:\t{1}", mostCalled[i].phoneNumber, mostCalled[i].callsNumber);
            }

            Console.WriteLine("\n5 Most active: \n(number: calls\tsms\tmetric)");
            SubscriberStats[] mostActive = mobileOperator.GetMostActiveSubscribers(5);
            for (int i = 0; i < mostActive.Length; i++)
            {
                Console.WriteLine("{0}:\t{1}\t{2}\t{3}", mostActive[i].phoneNumber, mostActive[i].callsNumber, mostActive[i].smsNumber, mostActive[i].metric);
            }

            Console.WriteLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int            maxPhoneNum       = 380000;
            MobileOperator Verizon           = new MobileOperator(maxPhoneNum);
            MobileAccount  firstSubscriber   = new MobileAccount(Verizon, 1);
            MobileAccount  secondSubscriber  = new MobileAccount(Verizon, 2);
            MobileAccount  anotherSubscriber = new MobileAccount(Verizon);

            Console.WriteLine("Number generated automatically for third subscriber: {0}",
                              anotherSubscriber.Number);

            secondSubscriber.AddNumberToPhoneBook(1, "Ramin Djavadi");
            firstSubscriber.AddNumberToPhoneBook(2, "Jonathan Nolan");

            Console.WriteLine("\nSms from someone you know:");
            firstSubscriber.SendSms(2, "Hello, how 're you?");
            secondSubscriber.SendSms(1, "Fine, thanks");

            Console.WriteLine("\nSms from someone you don't:");
            anotherSubscriber.SendSms(1, "Where's my money?");

            Console.WriteLine("\nCalls:");
            anotherSubscriber.MakeCall(1);
            firstSubscriber.MakeCall(2);

            Console.WriteLine("\nSubscribers number: {0}", Verizon.SubscribersCount);
            Console.ReadLine();
        }
Beispiel #3
0
        public static void ShowSms(MobileOperator mobileOperator)
        {
            MobileAccount firstSubscriber   = new MobileAccount(mobileOperator, 1);
            MobileAccount secondSubscriber  = new MobileAccount(mobileOperator, 2);
            MobileAccount anotherSubscriber = new MobileAccount(mobileOperator);

            Console.WriteLine("Number generated automatically for third subscriber: {0}",
                              anotherSubscriber.Number);

            secondSubscriber.AddNumberToPhoneBook(1, "Ramin Djavadi");
            firstSubscriber.AddNumberToPhoneBook(2, "Jonathan Nolan");

            mobileOperator.AddFunds(1, 4);
            mobileOperator.AddFunds(2, 4);
            mobileOperator.AddFunds(anotherSubscriber.Number, 2);

            Console.WriteLine("\nSms from someone you know:");
            firstSubscriber.SendSms(2, "Hello, how 're you?");
            secondSubscriber.SendSms(1, "Fine, thanks");

            Console.WriteLine("\nSms from someone you don't:");
            anotherSubscriber.SendSms(1, "Where's my money?");

            Console.WriteLine();
        }
Beispiel #4
0
        public void HandleCall(MobileAccount sender, int receiver)
        {
            MobileAccount mobileAccount = GetAccountByNumber(receiver);

            mobileAccount.ReceiveCall(sender.Number);
            callsJournal.Add(new KeyValuePair <int, int>(sender.Number, receiver));
        }
Beispiel #5
0
        public void HandleSms(MobileAccount sender, int receiver, string text)
        {
            MobileAccount mobileAccount = GetAccountByNumber(receiver);

            mobileAccount.ReceiveSms(sender.Number, text);
            smsJournal.Add(new KeyValuePair <int, int>(sender.Number, receiver));
        }
Beispiel #6
0
 public void Register(MobileAccount mobileAccount)
 {
     try {
         this.subscribers.Add(mobileAccount.Number, mobileAccount);
     } catch (ArgumentException) {
         throw new ArgumentException(
                   String.Format("Such number({0}) already exists!",
                                 mobileAccount.Number)
                   );
     }
 }
Beispiel #7
0
        public MobileAccount GetAccountByNumber(int number)
        {
            MobileAccount mobileAccount = null;

            try {
                mobileAccount = subscribers[number];
            } catch (Exception) {
                throw new ArgumentException("No such number in the network");
            }
            return(mobileAccount);
        }
Beispiel #8
0
        public static void ShowCalls(MobileOperator mobileOperator)
        {
            Console.WriteLine("\nCalls:");
            MobileAccount thirdSubscriber  = new MobileAccount(mobileOperator, 3);
            MobileAccount fourthSubscriber = new MobileAccount(mobileOperator, 4);

            thirdSubscriber.MakeCall(4);
            fourthSubscriber.MakeCall(3);
            fourthSubscriber.MakeCall(1);

            Console.WriteLine();
        }
Beispiel #9
0
        public int GetFreeNumber()
        {
            int number = 0;

            try {
                while (true)
                {
                    number = numberGenerator.Next(MinNumber, MaxNumber + 1);
                    MobileAccount acc = this.subscribers[number];
                }
            } catch (Exception) {
                return(number);
            }
        }
Beispiel #10
0
        public OperatorMessage HandleSms(MobileAccount sender, int receiver, string text)
        {
            MobileAccount mobileAccount = GetAccountByNumber(receiver);

            if (moneyOnAccount[sender.Number] < this.SmsPricing)
            {
                return(new OperatorErrorMessage()
                {
                    Text = "Insufficient funds. You have: $" + moneyOnAccount[sender.Number]
                });
            }
            moneyOnAccount[sender.Number] -= this.SmsPricing;
            mobileAccount.ReceiveSms(sender.Number, text);
            smsJournal.Add(new KeyValuePair <int, int>(sender.Number, receiver));
            return(new OperatorInfoMessage());
        }
Beispiel #11
0
        public void HandleSms(MobileAccount sender, int receiver, string text)
        {
            MobileAccount mobileAccount = GetAccountByNumber(receiver);

            mobileAccount.ReceiveSms(sender.Number, text);
        }
Beispiel #12
0
        public void HandleCall(MobileAccount sender, int receiver)
        {
            MobileAccount mobileAccount = GetAccountByNumber(receiver);

            mobileAccount.ReceiveCall(sender.Number);
        }