Пример #1
0
        public static void Start()
        {
            //Create an instance of the GSM class.
            var myPhone = new GSM("GalaxyS6", "Samsung");

            //Add few calls.
            myPhone.AddCall(new Call(new DateTime(2015, 3, 5, 9, 30, 10), "0883448036", 140));
            myPhone.AddCall(new Call(new DateTime(2015, 3, 4, 10, 12, 53), "0883428135", 230));
            myPhone.AddCall(new Call(new DateTime(2015, 3, 12, 19, 3, 32), "0883451438", 423));

            //Print call information
            myPhone.PrintCallHistory();
            Console.WriteLine();

            //Print the total price of the calls in the history for 0.37 per minute
            Console.WriteLine("Total calls price: ${0:0.##}", myPhone.GetCallsTotalPrise(0.37M));

            //Remove the longest call from the history and calculate the total price again
            var longestCall = myPhone.CallHistory.OrderByDescending(x => x.Duration).First();
            myPhone.DeleteCall(longestCall);
            Console.WriteLine("Longest call removed!");
            Console.WriteLine("Total calls price: ${0:0.##}", myPhone.GetCallsTotalPrise(0.37M));
            Console.WriteLine();
            myPhone.PrintCallHistory();

            //Finally clear the call history and print it.
            myPhone.ClearHistory();
            Console.WriteLine("History cleared!");
            myPhone.PrintCallHistory();
        }
Пример #2
0
        static void Main()
        {
            Display someDisplay = new Display("4.5inch", "165Million");
            Battery someBattery = new Battery("Varta", 10.00, 10.00);

            GSM myPhone = new GSM("G3", "JIAYU", "Pencho", 390.00m, someBattery, someDisplay);

            myPhone.AddCallToHist(DateTime.Now, "088617555", 180);
            myPhone.AddCallToHist(DateTime.Now, "099953312", 2000);
            myPhone.AddCallToHist(DateTime.Now, "125989364", 369);
            myPhone.AddCallToHist(DateTime.Now, "058933153", 600);

            myPhone.DisplayCallHistory();
            Console.WriteLine("Price for all calls");
            //calculating totalPrice for all calls
            decimal pricePerMinute = 0.37m;
            decimal totalPrice = 0m;
            totalPrice=myPhone.TotalPriceCall(pricePerMinute);
            Console.WriteLine(totalPrice);

            //Remove LongestCall and calculating price again
            myPhone.RemoveLongestCall();
            Console.WriteLine("Price for all calls after removing the longest call");
            totalPrice = myPhone.TotalPriceCall(pricePerMinute);
            Console.WriteLine(totalPrice);
            myPhone.DisplayCallHistory();
            myPhone.ClearCallHistory();
            Console.WriteLine("This is cleared call history:");
            myPhone.DisplayCallHistory();
        }
        // The following method is executed in the Main() method which is located in the TestExecution class
        public static void CallHistoryTest()
        {
            GSM myGSM = new GSM("Galaxy Note III", "Samsung");  // Initialize a new phone

            myGSM.AddCall(DateTime.Now.AddSeconds(8432), "0888123456", 36);         // Stuff it's call history with entries
            myGSM.AddCall(DateTime.Now.AddSeconds(12415), "+359888123456", 511);
            myGSM.AddCall(DateTime.Now.AddSeconds(22425), "0877123456", 14);
            myGSM.AddCall(DateTime.Now.AddSeconds(29434), "+359888123456", 643);
            myGSM.AddCall(DateTime.Now.AddSeconds(42213), "0899123456", 186);
            myGSM.AddCall(DateTime.Now.AddSeconds(52411), "+359888123456", 152);

            myGSM.DisplayCallHistory(); // Display the call history
            Console.WriteLine();
            Console.WriteLine("Price: {0:f2}", myGSM.TotalPrice(.37));  // Display the price for all the entries
            Console.WriteLine();

            myGSM.DeleteCall(FindIndexOfLongestCall(myGSM));    // Remove the entry at the index where the longest call is kept

            myGSM.DisplayCallHistory();
            Console.WriteLine();
            Console.WriteLine("Price: {0:f2}", myGSM.TotalPrice(.37));  // Display the price for the entries that remain
            Console.WriteLine();

            myGSM.ClearHistory();       // Clear the history

            myGSM.DisplayCallHistory();
            Console.WriteLine();
            Console.WriteLine("Price: {0:f2}", myGSM.TotalPrice(.37));
            Console.WriteLine();
        }
Пример #4
0
        static void Main()
        {
            //the data is fake
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
            GSM[] gsms = new GSM[3];

            Display display1 = new Display(4F, "16M");
            Battery battery1 = new Battery(450, 30, BatteryType.NiCd);
            gsms[0] = new GSM("Nokia 808", "Nokia Corporation", 345.00M, "Petar Petrov", battery1, display1);

            Display display2 = new Display(2.5F, "256K");
            Battery battery2 = new Battery(950, 35, BatteryType.LiIon);
            gsms[1] = new GSM("Samsung Ace", "Samsung Group", 545.00M, "Ivan Ivanov", battery2, display2);

            Display display3 = new Display(5.1F, "16M");
            Battery battery3 = new Battery(700, 25, BatteryType.NiMH);
            gsms[2] = new GSM("Motorola", "Motorola Solutions, Inc.", 45.00M, "Vasil Vasilev", battery3, display3);

            foreach (var gsm in gsms)
            {
                Console.WriteLine(gsm.ToString());
                Console.WriteLine();
            }

            //Display the information about the static property IPhone4S.
            GSM.IPhone4S.Owner = "Alis";
            Console.WriteLine(GSM.IPhone4S.ToString());
        }
 //add few calls in the phone
 public GSMCallHistoryTest()
 {
     phone = new GSM("Diamond", "HTC", "Pesho", 700.0, battery1, display1);
     phone.AddCall("0888123456", 133, DateTime.Parse("22.02.2013"),TimeSpan.Parse("15:16"));
     phone.AddCall("0888000001", 15, DateTime.Parse("20.02.2013"), TimeSpan.Parse("10:20"));
     phone.AddCall("0888000002", 62, DateTime.Parse("19.02.2013"), TimeSpan.Parse("22:30"));
 }
Пример #6
0
        static void Main(string[] args)
        {
            var device = new GSM("Touch Pro 2", "HTC", "Vlado");

            Call firstCall = new Call(180);
            device.AddCall(firstCall);

            Console.WriteLine(device.CallHystoryPrice());
        }
Пример #7
0
 //Static constructor
 static GSM()
 {
     galaxyS6 = new GSM("GalaxyS6", "Samsung")
     {
         Price = 1140.30m,
         Owner = "Jake Miller",
         battery = new Battery("Alk")
         {
             HoursIdle = 200,
             HoursTalk = 40,
             Type = BatteryType.LiIon
         },
         Display = new Display(5.1, 16M)
     };
 }
        // Method used to find the index of the longest call in the call history
        static int FindIndexOfLongestCall(GSM myGSM)
        {
            uint maxDuration = 0;
            int indexOfLongestCall = 0;

            for (int i = 0; i < myGSM.CallHistory.Count; i++)
            {
                if (myGSM.CallHistory[i].CallDuration > maxDuration)
                {
                    maxDuration = myGSM.CallHistory[i].CallDuration;
                    indexOfLongestCall = i;
                }
            }

            return indexOfLongestCall;
        }
Пример #9
0
        // The following method is executed in the Main() method which is located in the TestExecution class
        public static void Test()
        {
            GSM[] GSMArray = new GSM[6];    // Each of the elements is initialized by using all the different constructors

            GSMArray[0] = new GSM("One", "HTC");
            GSMArray[1] = new GSM("Lumia 1020", "Nokia", 1299.00);
            GSMArray[2] = new GSM("Galaxy S4", "Samsung", 899.00, "Pesho Peshov");
            GSMArray[3] = new GSM("ATIV S", "Samsung", 599.00, new Battery("I8750", 168, 8, BatteryType.LiIon));
            GSMArray[4] = new GSM("Windows Phone 8X", "HTC", 699.00, new Display(4.3, 16000000));
            GSMArray[5] = GSM.IPhone4S;

            for (int i = 0; i < GSMArray.Length; i++)  // Use the overridden ToString method to display the phone info on the console
            {
                Console.WriteLine(GSMArray[i].ToString());
                Console.WriteLine();
            }
        }
Пример #10
0
        public static void Start()
        {
            //Array of GSM objects
            var gsmDevices = new GSM[]
            {
                new GSM("HTC One", "HTC"),
                new GSM("Lumia", "Nokia"),
                new GSM("iPhone 4S", "Apple"),
                new GSM("Galaxy S6 Edge", "Samsung"),

            };

            //Display info about each object
            foreach (var gsmDevice in gsmDevices)
            {
                Console.WriteLine(gsmDevice.ToString());
            }

            //Disaply GalaxyS6 info
            Console.WriteLine(GSM.GalaxyS6.ToString());
        }
Пример #11
0
        static void Main(string[] args)
        {
            //Create an array of few instances of the GSM class.
            GSM[] gsmArray = new GSM[3];
            Display display = new Display(4.8, 16000000);
            Battery battery = new Battery("NiMH", 30.7, 6.7);
            battery.batteryType = BatteryType.NiMH;

            //initialize the phones
            gsmArray[0] = new GSM("Galaxy SIII", "Samsung", 870, "Samuel L. Jackson", battery, display);
            gsmArray[1] = new GSM("Milestone 2", "Motorola", 300, "Garry Barlow", battery, display);
            gsmArray[2] = new GSM("Sony", "Xperia 8", 220, "Zigs Gugenheim", battery, display);

            //Display the information about the GSMs in the array.
            for (int i = 0; i < gsmArray.Length; i++)
            {
                Console.WriteLine(gsmArray[i]);
            }

            //Display the information about the static property IPhone4S
            Console.WriteLine(GSM.IPhone4S);
        }
Пример #12
0
 static GSM()
 {
     iPhone4S = new GSM("iPhone4S", "Apple", 700m, null,
         new Battery("AppleBattery", new TimeSpan(30, 27, 0), new TimeSpan(16, 22, 0),
         BatteryType.LiIon), new Display(4.1m, "16M"));
 }