Beispiel #1
0
        static void Main(string[] args)
        {
            int        n      = int.Parse(Console.ReadLine());
            List <GSM> phones = new List <GSM>();

            for (int i = 0; i < n; i++)
            {
                string line = Console.ReadLine();
                if (line == "Nokia95")
                {
                    phones.Add(GSM.NokiaN95);
                }
                else
                {
                    string[] arguments = line.Split(';');
                    if (arguments.Count() == 4)
                    {
                        GSM newPhone = new GSM(arguments[0], arguments[1], double.Parse(arguments[2]), arguments[3]);
                        phones.Add(newPhone);
                    }
                    else
                    {
                        GSM newPhone = new GSM(arguments[0], arguments[1], double.Parse(arguments[2]), arguments[3], arguments[4], int.Parse(arguments[5]), int.Parse(arguments[6]), double.Parse(arguments[7]), int.Parse(arguments[8]));
                        phones.Add(newPhone);
                    }
                }
            }

            foreach (GSM phone in phones)
            {
                Console.WriteLine(phone);
            }
        }
Beispiel #2
0
        public static void TestedGSM()
        {
            GSM SONY    = new GSM("XPERIA Z", "Sony Corp.", new Battery(BatteryType.Li_Ion, 500, 150), new Display(5, 16000000));
            GSM Samsung = new GSM("Galaxy S5", "Samsung Corp.", new Battery(BatteryType.Li_Poly, 600, 200), new Display(5, 16000000));
            GSM HTC     = new GSM("One X8", "HTC Corp.", new Battery(BatteryType.NiCd, 450, 100), new Display(4.8, 16000000));

            GSM[] gsms = new GSM[] { SONY, Samsung, HTC };

            StringBuilder testedGSM = new StringBuilder();

            for (int i = 0; i < gsms.Length; i++)
            {
                testedGSM.AppendLine(gsms[i].ToString());
                testedGSM.AppendLine();
            }

            testedGSM.AppendLine(GSM.IPhone4S.ToString());
            Console.WriteLine(testedGSM.ToString());
        }
        public static void TestHistoryCalls()
        {
            GSM gsm = new GSM("XPERIA", "Sony Corp.", new Battery(BatteryType.Li_Ion, 1000, 500), new Display(5, 16000000));

            gsm.AddCall(new Call("0888123456", 300));
            gsm.AddCall(new Call("0888654321", 100));
            gsm.AddCall(new Call("0888888888", 200));

            decimal totalPriceOfCalls = gsm.CalculateTotalCallPrice((decimal)0.37);

            Console.WriteLine("Total price of the calls is: {0} BGN", totalPriceOfCalls);

            Call longestCall = FindLongestCall(gsm);

            gsm.DeleteCall(longestCall);

            totalPriceOfCalls = gsm.CalculateTotalCallPrice((decimal)0.37);

            Console.WriteLine("Total price after remove longest call is: {0} BGN", totalPriceOfCalls);

            gsm.ClearCallHistory();
        }
        private static Call FindLongestCall(GSM gsm)
        {
            Call longestCall = gsm.CallHistory.OrderBy(c => c.Duration).Last();

            return(longestCall);
        }