예제 #1
0
        /*
         * Use it to set the static Iphone propery as well as a static metod for the GSM class
         * which returns a new GSM instance wit iPhone4S parameters
         * (this is outside the homework, jut made it to check how it works)
         */

        // static public methods
        public static GSM SetIphone4S()
        {
            string  iPhoneModel = "Iphone4S";
            Battery ibattery    = new Battery("bullshit", Manufacturers.APPLE, BatteryTypes.NiCd, 10, 2);
            Display idisplay    = new Display("iShit", Manufacturers.SHARP, 256, 3.5M);
            string  iOwner      = "iDiot";
            int     iPrice      = int.MaxValue;

            GSM iphone4S = new GSM(iPhoneModel, Manufacturers.APPLE, iPrice, iOwner, ibattery, idisplay);

            return(iphone4S);
        }
예제 #2
0
        static void Main(string[] args)
        {
            //////GSM

            GSM[] gsm = new GSM[5];

            gsm[0] = new GSM("S8", "Samsung", 900.0, "Ivan", new Battery(BatteryType.LiIon), new Display(5.8, "16M"));
            gsm[1] = new GSM("razr 2019", "Motorola", 1500.0, "Georgi", new Battery(BatteryType.LiIon), new Display(6.3, "16M"));
            gsm[2] = GSM.IPhone4S;
            gsm[3] = new GSM("Z6 Pro", "Lenovo");
            gsm[4] = new GSM("P40 Pro", "Huawei", 1186.40, new Battery(), new Display(6.58));

            for (int i = 0; i < gsm.Length; i++)
            {
                Console.WriteLine("GSM {0} :", i + 1);
                Console.WriteLine(new string('-', 20));
                Console.WriteLine(gsm[i]);
                Console.WriteLine(new string('*', 35));
            }

            //////Cals

            Call[] calls = new Call[5];
            calls[0] = new Call(DateTime.Now, "0876 444 162", 55);
            calls[1] = new Call(DateTime.Now, "0876 965 982", 958);
            calls[2] = new Call(DateTime.Now, "0896 444 365", 1023);
            calls[3] = new Call(DateTime.Now, "0886 365 162", 235);
            calls[4] = new Call(DateTime.Now, "0877 141 580", 25);

            for (int i = 0; i < calls.Length; i++)
            {
                gsm[0].AddCall(calls[i]);
            }

            gsm[0].PrintCalls();
            gsm[0].GetTotalPrice();

            gsm[0].DeleteCalls(calls[2].DialedPhoneNumber);
            gsm[0].PrintCalls();
            gsm[0].GetTotalPrice();

            gsm[0].DeleteCalls(calls[3].DialedPhoneNumber);
            gsm[0].PrintCalls();
            gsm[0].GetTotalPrice();

            gsm[0].ClearCalls();
            gsm[0].PrintCalls();
            gsm[0].GetTotalPrice();
        }
예제 #3
0
        // The bigger mess :)
        public static void StarCallHistoryTests()
        {
            // initialize new GSM instance (using the built-in iShit)
            GSM newPhone = GSM.Iphone4S;

            // initialize list to store the call, this is not the call histori, just to automate the proces of making calls
            List <Call> callsList = new List <Call>();

            // random generator for multiple purposes
            Random rnd = new Random();

            // let's start calling
            for (int i = 0; i < 10; i++)
            {
                // making some numbers
                string number = String.Format
                                    ("+3598{0}{1}{2}{3}{4}{5}{6}{7}{8}",
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10),
                                    rnd.Next(0, 10));

                // initialize Call instance
                Call currCall = new Call(DateTime.Now.AddMinutes((double)(rnd.Next(10, 50000))), number, rnd.Next(0, 1000));

                // Adding the new call to the list of call, still not to the call history
                callsList.Add(currCall);
            }

            // new list of call - sorted by time of call because the time of call is ramdom but it is normal the call to be sorted by time of call
            var callListSortedBytimeOfCall = callsList.OrderBy(x => x.DateOfCall);

            // now our call from the list are added to the phon's call history
            foreach (var call in callListSortedBytimeOfCall)
            {
                newPhone.AddCall(call);
            }

            // printing call history (from GSM )
            Console.WriteLine(newPhone.ShowCallHistory());

            // printing the bill
            Console.WriteLine("Total amount from call histori is {0}\n", newPhone.CalculeteTotalPriceOfCalls());

            // every time that index must be different because of the random character of the call history
            Console.Write("Enter the index of the longest call: ");
            int index = int.Parse(Console.ReadLine());

            // deleting the longest call (if you enter the correct index, else other than the longest call will be delited)
            newPhone.DeliteCall(index);
            Console.WriteLine("\nTotal amount from call histori is {0}\n", newPhone.CalculeteTotalPriceOfCalls());

            // chech again the call history to see that the delited call is no longer in the history
            Console.WriteLine(newPhone.ShowCallHistory());

            // clear all call from the history (the call in the list are still there)
            newPhone.ClearCallHistory();

            // check again the history to confirm that it is empty
            Console.WriteLine(newPhone.ShowCallHistory());
        }