Example #1
0
 // Static constructor for setting the iPhone4S field
 static Gsm()
 {
     iPhone4S = new Gsm();
     iPhone4S.Model = "iPhone4S";
     iPhone4S.Manufacturer = "Apple";
     iPhone4S.Battery = new Battery("ABC123", 200, 14, BatteryType.LiIon);
     iPhone4S.Display = new Display(3.5, 16777216);
 }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            string decorationLine = new string('-', 80);
            Console.Write(decorationLine);
            Console.WriteLine("***Entering the call history for a mobile phone, modifying and displaying it***");
            Console.Write(decorationLine);

            //#region User-defined input
            //Console.WriteLine("---First enter information about the mobile phone---");
            //Console.Write("Enter model: ");
            //string model = Console.ReadLine();
            //Console.Write("Enter manufacturer: ");
            //string manufacturer = Console.ReadLine();
            //Console.Write("Enter price: ");
            //double price = double.Parse(Console.ReadLine());
            //Console.Write("Enter owner's first name: ");
            //string ownerFirstName = Console.ReadLine();
            //Console.Write("Enter owner's last name: ");
            //string ownerLastName = Console.ReadLine();
            //string owner = ownerFirstName + " " + ownerLastName;
            //Console.WriteLine("---Getting information about the mobile phone's battery---");
            //Console.Write("Enter model: ");
            //string batteryModel = Console.ReadLine();
            //Console.Write("Enter idle hours: ");
            //double batteryIdleHours = double.Parse(Console.ReadLine());
            //Console.Write("Enter talk hours: ");
            //double battertTalkHours = double.Parse(Console.ReadLine());
            //Console.Write("Enter battery type (LiIon/NiMH/NiCd/NiZn): ");
            //BatteryType batteryType;
            //switch (Console.ReadLine().ToLower())
            //{
            //    case "liion":
            //    case "li-ion":
            //        batteryType = BatteryType.LiIon;
            //        break;
            //    case "nimh":
            //        batteryType = BatteryType.NiMH;
            //        break;
            //    case "nicd":
            //        batteryType = BatteryType.NiCd;
            //        break;
            //    case "nizn":
            //        batteryType = BatteryType.NiZn;
            //        break;
            //    default:
            //        batteryType = (BatteryType)int.MinValue;
            //        break;
            //}
            //Battery battery = new Battery(batteryModel, batteryIdleHours, battertTalkHours, batteryType);
            //Console.WriteLine("---Getting information about the mobile phone's display---");
            //Display display = new Display();
            //Console.Write("Enter size in inches: ");
            //display.SizeInInches = double.Parse(Console.ReadLine());
            //Console.Write("Enter number of colors: ");
            //display.NumberOfColors = int.Parse(Console.ReadLine());
            //Gsm mobilePhone = new Gsm(model, manufacturer, price, owner, battery, display);

            //Console.WriteLine("---Now entering some calls in the history---");
            //Console.Write("Enter how many call you want to add: ");
            //int numberfOfCalls = int.Parse(Console.ReadLine());
            //for (int call = 0; call < numberfOfCalls; call++)
            //{
            //    Console.Write("Enter call date in format 'month/day/year': ");
            //    string callDate = Console.ReadLine();
            //    Console.Write("Enter call time in format 'HH:minutes:seconds': ");
            //    string callTime = Console.ReadLine();
            //    DateTime callDateAndTime = DateTime.ParseExact(callDate + " " + callTime, "M/d/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
            //    Console.Write("Enter the phone number the call is made to: ");
            //    string toPhoneNumber = Console.ReadLine();
            //    Console.Write("Enter the duration of the call in seconds: ");
            //    int durationInSeconds = int.Parse(Console.ReadLine());
            //    mobilePhone.AddToCallHistory(new Call(callDateAndTime, toPhoneNumber, durationInSeconds));
            //}
            //#endregion

            #region Hard-coded input
            Gsm mobilePhone = new Gsm();
            mobilePhone.Model = "GS290";
            mobilePhone.Manufacturer = "LG";
            mobilePhone.Price = 189.29;
            mobilePhone.Owner = "Pesho Peshov";
            mobilePhone.Battery = new Battery("ABC321", 70, 6.5, BatteryType.LiIon);
            mobilePhone.Display = new Display(2.2, 2000000);

            Call firstCall = new Call(new DateTime(2013, 2, 12, 22, 22, 22, DateTimeKind.Unspecified), "0888888888", 152);
            mobilePhone.AddToCallHistory(firstCall);
            Call secondCall = new Call(new DateTime(2013, 2, 22, 11, 11, 11, DateTimeKind.Unspecified), "08777777777", 151);
            mobilePhone.AddToCallHistory(secondCall);
            Call thirdCall = new Call(new DateTime(2013, 2, 5, 9, 9, 9, DateTimeKind.Unspecified), "0899999999", 152);
            mobilePhone.AddToCallHistory(thirdCall);
            #endregion
            Console.WriteLine("---Now displaying the information about the calls---");
            foreach (Call call in mobilePhone.CallHistory)
            {
                Console.WriteLine(call.ToString());
                Console.WriteLine();
            }

            Console.WriteLine("---Now displaying the total price of the calls---");
            Console.WriteLine("{0:F2}", mobilePhone.CalculateTotalPrice(0.37));
            Console.WriteLine();

            Call longestCall = mobilePhone.CallHistory[0];
            foreach (Call call in mobilePhone.CallHistory)
            {
                if (call.Duration > longestCall.Duration)
                {
                    longestCall = call;
                }
            }
            mobilePhone.DeleteFromCallHistory(longestCall);
            Console.WriteLine("---Now displaying the total price of the calls after removing \nthe longest call---");
            Console.WriteLine("{0:F2}", mobilePhone.CalculateTotalPrice(0.37));
            Console.WriteLine();

            mobilePhone.ClearCallHistory();
            Console.WriteLine("---Now displaying the call history after clearing it---");
            foreach (Call call in mobilePhone.CallHistory)
            {
                Console.WriteLine(call);
            }
        }
Example #3
0
        static void Main()
        {
            string decorationLine = new string('-', 80);
            Console.Write(decorationLine);
            Console.WriteLine("***Entering and displaying the information about mobile phone devices***");
            Console.Write(decorationLine);

            Gsm[] mobilePhones;
            //#region User-defined input
            //Console.Write("Enter the number of mobile phone devices: ");
            //int numberOfMobilePhones = int.Parse(Console.ReadLine());
            //mobilePhones = new Gsm[numberOfMobilePhones];
            //for (int index = 0; index < numberOfMobilePhones; index++)
            //{
            //    Console.WriteLine("---Getting information about a mobile phone---");
            //    Console.Write("Enter model: ");
            //    string model = Console.ReadLine();
            //    Console.Write("Enter manufacturer: ");
            //    string manufacturer = Console.ReadLine();
            //    Console.Write("Enter price: ");
            //    double price = double.Parse(Console.ReadLine());
            //    Console.Write("Enter owner's first name: ");
            //    string ownerFirstName = Console.ReadLine();
            //    Console.Write("Enter owner's last name: ");
            //    string ownerLastName = Console.ReadLine();
            //    string owner = ownerFirstName + " " + ownerLastName;
            //    Console.WriteLine("---Getting information about the mobile phone's battery---");
            //    Console.Write("Enter model: ");
            //    string batteryModel = Console.ReadLine();
            //    Console.Write("Enter idle hours: ");
            //    double batteryIdleHours = double.Parse(Console.ReadLine());
            //    Console.Write("Enter talk hours: ");
            //    double battertTalkHours = double.Parse(Console.ReadLine());
            //    Console.Write("Enter battery type (LiIon/NiMH/NiCd/NiZn): ");
            //    BatteryType batteryType;
            //    switch (Console.ReadLine().ToLower())
            //    {
            //        case "liion":
            //        case "li-ion":
            //            batteryType = BatteryType.LiIon;
            //            break;
            //        case "nimh":
            //            batteryType = BatteryType.NiMH;
            //            break;
            //        case "nicd":
            //            batteryType = BatteryType.NiCd;
            //            break;
            //        case "nizn":
            //            batteryType = BatteryType.NiZn;
            //            break;
            //        default:
            //            batteryType = (BatteryType)int.MinValue;
            //            break;
            //    }
            //    Battery battery = new Battery(batteryModel, batteryIdleHours, battertTalkHours, batteryType);
            //    Console.WriteLine("---Getting information about the mobile phone's display---");
            //    Display display = new Display();
            //    Console.Write("Enter size in inches: ");
            //    display.SizeInInches = double.Parse(Console.ReadLine());
            //    Console.Write("Enter number of colors: ");
            //    display.NumberOfColors = int.Parse(Console.ReadLine());
            //    mobilePhones[index] = new Gsm(model, manufacturer, price, owner, battery, display);
            //    Console.WriteLine();
            //}
            //#endregion

            #region Hard-coded input
            mobilePhones = new Gsm[3];

            Gsm firstGsm = new Gsm();
            firstGsm.Model = "GS290";
            firstGsm.Manufacturer = "LG";
            firstGsm.Price = 189.29;
            firstGsm.Owner = "Pesho Peshov";
            firstGsm.Battery = new Battery("ABC321", 70, 6.5, BatteryType.LiIon);
            firstGsm.Display = new Display(2.2, 2000000);

            Battery secondPhoneBattery = new Battery();
            secondPhoneBattery.Model = "XY456";
            secondPhoneBattery.HoursIdle = 90;
            secondPhoneBattery.HoursTalk = 7;
            secondPhoneBattery.Type = BatteryType.LiIon;
            Display secondPhoneDisplay = new Display();
            secondPhoneDisplay.NumberOfColors = 2000000;
            secondPhoneDisplay.SizeInInches = 2.6;
            Gsm secondGsm = new Gsm("C-5", "Nokia", 199.99, "Gosho Goshov", secondPhoneBattery, secondPhoneDisplay);

            Gsm thirdGsm = new Gsm("One", "HTC");
            thirdGsm.Price = 700.99;
            thirdGsm.Owner = "Petko Petkov";
            thirdGsm.Battery = new Battery();
            thirdGsm.Battery.Model = "XYZ987";
            thirdGsm.Battery.HoursIdle = 70;
            thirdGsm.Battery.Type = BatteryType.NiMH;
            thirdGsm.Display = new Display(4.7, 16000000);

            mobilePhones[0] = firstGsm;
            mobilePhones[1] = secondGsm;
            mobilePhones[2] = thirdGsm;
            #endregion

            Console.WriteLine("---Displaying the information about all the mobile phones you've entered---");
            foreach (Gsm mobilePhone in mobilePhones)
            {
                Console.WriteLine(mobilePhone.ToString());
                Console.WriteLine();
            }
            Console.WriteLine("---Now displaying the information about the iPhone4S---");
            Console.WriteLine(Gsm.IPhone4S.ToString());
        }