public void HistoryTest()
    {
        Console.WriteLine(new string('-', 50));
        Console.WriteLine("                  Calls history");
        Console.WriteLine(new string('-', 50));
        Console.WriteLine();
        GSM phone = new GSM();
        phone.AddHistory(DateTime.Now, "0891234567", 10);
        phone.AddHistory(DateTime.Now, "0883456789", 47.99);
        phone.AddHistory(DateTime.Now, "0872345678", 89.01);
        phone.PrintCalls();

        Console.WriteLine();
        Console.WriteLine("Assuming the price per minute is 0.37! Calculate the total price of the calls:");
        Console.WriteLine(new string('-', 77));
        phone.CalculateTotalPrice();
        Console.WriteLine();
        Console.WriteLine();

        Console.WriteLine("Delete longest call from the history and calculate the total price again:");
        Console.WriteLine(new string('-', 74));
        phone.DeleteHistory(89.01);
        phone.CalculateTotalPrice();
        Console.WriteLine();
        Console.WriteLine();

        Console.WriteLine(new string('-', 50));
        Console.WriteLine("           Calls history after delete");
        Console.WriteLine(new string('-', 50));
        Console.WriteLine();
        phone.ClearHistory();
        phone.CalculateTotalPrice();
    }
        static void Main(string[] args)
        {
            var calls = new Call[]
            {
                new Call(DateTime.Now, TimeSpan.FromSeconds(52), "3598873629", 15),
                new Call(DateTime.Now, TimeSpan.FromSeconds(23), "3598546846", 25),
                new Call(DateTime.Now, TimeSpan.FromSeconds(45), "3597994516", 35)
            };

            var gsm = new GSM("6", "Nexus");

            gsm.AddCall(calls[0]);
            gsm.AddCall(calls[1]);
            gsm.AddCall(calls[2]);

            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine(call);
            }

            Console.WriteLine(gsm.CalculateTotalPrice(0.37m));

            gsm.DeleteCall(calls[2]);

            Console.WriteLine(gsm.CalculateTotalPrice(0.37m));

            gsm.ClearCall();

            Console.WriteLine(gsm.CalculateTotalPrice(0.37m));
        }
Esempio n. 3
0
        static void Main(string[] args)
        { //Problem 12. Call history test
            //12.1 Create an instance of the GSM class.
            GSM s8 = new GSM("Galaxy S8 Plus", "Samsung", "600$", owner: "Ben",
                             batterySpec: new Battery {
                BatteryModel = "Samsung 3500mAh battery", HoursIdle = 96, HoursTalk = 27, BatteryType = BatteryType.LiIon
            },
                             displaySpec: new Display());

            //12.2 Add few calls.
            int countOfCalls = 7;

            Call[] allCalls          = new Call[countOfCalls];
            int    clientPhoneNumber = 889977550;

            //set calls and their duration time//
            for (int index = 0; index < countOfCalls; index++)
            {
                clientPhoneNumber = clientPhoneNumber + index;                //simple random number adding
                allCalls[index]   = new Call();
                allCalls[index].DialedPhoneNumber = "0" + clientPhoneNumber;

                allCalls[index].Duration = 10 + index * 2;                       //duration is in seconds (start from 10 seconds for first call and increase for the next one)
            }

            s8.AddCalls(allCalls);

            //12.3 Display the information about the calls.
            Console.WriteLine(s8.CallHistoryToString());

            //12.4 Calculate and print the total price of the calls in the history. (the price per minute is 0.37$)
            Console.WriteLine("Total price of calls: " +
                              s8.CalculateTotalPrice(pricePerMinute: 0.37m) +
                              "$");

            //12.5 Remove the longest call from the history and calculate the total price again.

            //manually set duration time for testing purpose//
            allCalls[0].Duration = 480;  //set first call(889977550) to 8 min (this call duration, should be the longest one)

            //order by duration time (with lambda expression)
            var orderedCall = allCalls.OrderBy(x => x.Duration);
            var longestCall = orderedCall.Last();

            allCalls = orderedCall.ToArray();

            //add new ordered call history and delete the longest one
            s8.ClearCallHistory();
            s8.AddCalls(allCalls);
            s8.DeleteCalls(longestCall.DialedPhoneNumber);

            //calculate the total price
            Console.WriteLine("Total price of calls: " +
                              s8.CalculateTotalPrice() +
                              "$ (new calculation)");

            //12.6 Finally clear the call history
            s8.ClearCallHistory();
        }
Esempio n. 4
0
    public static void Test()
    {
        try
        {
            GSM Samsung = new GSM("Samsung S4", "Samsung", 1200, "Ivan", BatteryTypes.Lilon, 140, 23, 4.7, 512000);
            Samsung.AddCall(new Call("28.8.2013", "14:12:12", "+359125135123", 234));
            Samsung.AddCall(new Call("23.8.2013", "14:12:12", "+359125135123", 54));
            Samsung.AddCall(new Call("22.8.2013", "12:12:12", "+359125135123", 5234));
            Samsung.AddCall(new Call("25.8.2013", "19:12:12", "+359125135123", 34));
            Samsung.AddCall(new Call("22.8.2013", "14:0:12", "+359125135123", 2234));

            Console.WriteLine("Call history:");
            foreach (Call call in Samsung.CallHistory)
            {
                Console.WriteLine(call.ToString());
            }

            Console.WriteLine("\nTotal price of calls:" + Samsung.CalculateTotalPrice().ToString() + " lv");
            Samsung.DeleteCall(new Call("22.8.2013", "12:12:12", "+359125135123", 5234));

            Console.WriteLine("\nTotal price of calls after removing longest call:" + Samsung.CalculateTotalPrice().ToString() + " lv");

            Samsung.ClearCallHistory();

            Console.WriteLine("\nCall history after clearing it:");
            foreach (Call call in Samsung.CallHistory)
            {
                Console.WriteLine(call.ToString());
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
    static void Main()
    {
        GSM mobile = new GSM("3310", "Nokia");

        //Add some calls
        mobile.AddCallToHistory(new Call(DateTime.Now.AddDays(3), DateTime.Now.TimeOfDay, "0888123123", 120));
        mobile.AddCallToHistory(new Call(DateTime.Now.AddDays(5), DateTime.Now.TimeOfDay, "0888456456", 35));

        //Display call history and total price
        mobile.DisplayCallHistory();
        Console.WriteLine("Total price: {0:F2}", mobile.CalculateTotalPrice(0.37));
        Console.WriteLine();

        //Remove longest call and display total price again
        mobile.RemoveLongestCall();
        Console.WriteLine("Total price: {0:F2}", mobile.CalculateTotalPrice(0.37));
        Console.WriteLine();

        //Clear call history and print it
        mobile.ClearCallHistory();
        mobile.DisplayCallHistory();
    }
        static void Main()
        {
            GSM gsm = new GSM(new Display(10, 20, 5, 20), new Battery(BatteryType.NiCd, 43, 34), "Lumia", "Nokia", 100, "Pesho");
            var someCalls = new List<Call>();
            someCalls.Add(new Call(new DateTime(2015, 3, 13, 13, 24, 45), "0889666060", 100));
            someCalls.Add(new Call(new DateTime(2015, 3, 11, 13, 4, 45), "0899606060", 2000));
            someCalls.Add(new Call(new DateTime(2015, 3, 12, 13, 2, 4), "0899606060", 130));
            someCalls.Add(new Call(new DateTime(2015, 3, 3, 13, 24, 5), "0899606060", 400));
            foreach (var call in someCalls)
            {
                gsm.AddCall(call);
            }

            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine("Date: {0}.{1}.{2} - {3}:{4}:{5}, Phone number: {6}, Duration: {7}s", call.Date.Day, call.Date.Month, call.Date.Year,
                    call.Date.Hour, call.Date.Minute, call.Date.Second, call.DilledPhoneNumber, call.DurationOfCall);
            }

            decimal  resultTotalPrice = gsm.CalculateTotalPrice(gsm.CallHistory);
            Console.WriteLine("Total price of all calls: {0:F2}", resultTotalPrice);

            int longestCall = 0;
            int indexOfLongestCall = 0;
            for(int i = 0; i < gsm.CallHistory.Count; i++)
            {
                if(gsm.CallHistory[i].DurationOfCall > longestCall)
                {
                    longestCall = gsm.CallHistory[i].DurationOfCall;
                    indexOfLongestCall = i;
                }
            }

            gsm.DeleteCall(indexOfLongestCall);
            resultTotalPrice = gsm.CalculateTotalPrice(gsm.CallHistory);
            Console.WriteLine("Total price without longest call: {0:F2}", resultTotalPrice);
            gsm.ClearCallHistory();
        }
Esempio n. 7
0
    static void Main()
    {
        //GSM Test
        //Task 7
        Console.WriteLine("Test 1:");
        GSM myGSM = new GSM("Xperia SP", "Sony");
        GSM.PrintGSMCharacteristics(myGSM);

        Console.WriteLine();
        Console.WriteLine("Test 2:");
        myGSM.Price = 330;
        myGSM.Battery.BatType = BatteryType.LiIon;
        myGSM.Battery.HoursTalk = 13;
        myGSM.Battery.Model = "AB/D-F G";
        GSM.PrintGSMCharacteristics(myGSM);

        Console.WriteLine();
        Console.WriteLine("Test 3:");
        myGSM.Display.Size = 4.3;
        myGSM.Display.NumberOfColours = 16000000;
        GSM.PrintGSMCharacteristics(myGSM);

        Console.WriteLine();
        Console.WriteLine("Test 4:");
        GSM doughtersGSM = new GSM("Desire 500", "HTC");
        doughtersGSM.Owner = "Sofi";
        doughtersGSM.Price = 230.5;
        doughtersGSM.Battery.BatType = BatteryType.NiCd;
        doughtersGSM.Battery.Model = "afaf - asfg";
        doughtersGSM.Battery.HoursTalk = 14.5;
        doughtersGSM.Battery.HoursIdle = 240;
        doughtersGSM.Display.Size = 4;
        doughtersGSM.Display.NumberOfColours = 16000000;
        GSM.PrintGSMCharacteristics(doughtersGSM);

        Console.WriteLine();
        Console.WriteLine("Test 5:");
        GSM wifeGSM = new GSM("C7", "Nokia", 350.4, "Zorka");
        wifeGSM.Display = new Display(3.6, 1000000);
        GSM.PrintGSMCharacteristics(wifeGSM);

        GSM fatherGSM = new GSM("100", "Nokia");
        fatherGSM.Battery = new Battery();

        //Task 7 - Create an array of few instances of the GSM class.
        //Display the information about the GSMs in the array.
        //Display the information about the static property IPhone4S.
        Console.WriteLine();
        Console.WriteLine("Print all GSMs from a list:");
        List<GSM> gsmList = new List<GSM> { myGSM, doughtersGSM, wifeGSM, fatherGSM };

        foreach (var item in gsmList)
        {
            GSM.PrintGSMCharacteristics(item);
            Console.WriteLine();
        }

        GSM IPhone = GSM.IPhone4S;
        GSM.PrintGSMCharacteristics(IPhone);

        //Task 12 - GSMCallHistoryTest - I decided to combine GSM Test and GSMCallHistoryTest
        Console.WriteLine();
        Console.WriteLine("Call History Test:");
        GSM testGSM = new GSM("100", "Nokia");
        Call call1 = new Call(DateTime.Now, "14:59", 132, "0888 885 654");
        Call call2 = new Call(DateTime.Now, "15:39", 112, "0888 885 456");
        Call call3 = new Call(DateTime.Now, "16:22", 32, "0888 885 564");
        Call call4 = new Call(DateTime.Now, "17:15", 12, "0888 885 444");
        Call call5 = new Call(DateTime.Now, "18:12", 145, "0888 885 444");

        testGSM.AddNewCalls(call1);
        testGSM.AddNewCalls(call2);
        testGSM.AddNewCalls(call3);
        testGSM.AddNewCalls(call4);
        testGSM.AddNewCalls(call5);

        PrintCallHistory(testGSM);

        Console.WriteLine("GSM {1} {2} - Total cost of calls-->{0:f2}", testGSM.CalculateTotalPrice(0.37),
                    testGSM.Manifacturer, testGSM.Model);

        RemoveLongestCall(testGSM);
        Console.WriteLine();

        Console.WriteLine("After deleting the longest call, total cost is {0:f2}", testGSM.CalculateTotalPrice(0.37));
        Console.WriteLine();
        testGSM.ClearCallList();
        Console.WriteLine("New call history (after clearing the list):");
        PrintCallHistory(testGSM);
    }
Esempio n. 8
0
    public static void Main()
    {
        //Creating the instance of GSM.
        Battery litiumBattery = new Battery("Normal", 123, 20.5, BatteryType.LiIon);
        Display big = new Display(8.4, 3000);
        GSM myPhone = new GSM("W595", "Sony - Erikson", 678, "Cecilia", litiumBattery, big);

        //Adding few calls.
        Call[] calls = new Call[4];
        calls[0] = new Call(DateTime.Today, DateTime.Now, "0888123456", 123);
        calls[1] = new Call(DateTime.Today, DateTime.Now, "0877123456", 45);
        calls[2] = new Call(DateTime.Today, DateTime.Now, "0899123456", 540);
        calls[3] = new Call(DateTime.Today, DateTime.Now, "0789123456", 18);
        for (int i = 0; i < calls.Length; i++)
        {
            myPhone.AddHistory(calls[i]);
        }

        //Display calls information.
        foreach (var item in myPhone.callHistory)
        {
            Console.WriteLine("Date and time: {0}, Dialed phone: {1}, Duration: {2} seconds", item.Time, item.DialedPhone, item.Duration);
            Console.WriteLine();
        }

        //Print total price.
        Console.WriteLine();
        Console.WriteLine("The total price of the calls is {0:f2}", myPhone.CalculateTotalPrice(0.37));

        //Remove longest call and calculate price again.
        int longestCallIndex = 0;
        double longestDuration = 0.0;
        for (int i = 0; i < myPhone.callHistory.Count; i++)
        {
            if (myPhone.callHistory[i].Duration > longestDuration)
            {
                longestCallIndex = i;
                longestDuration = myPhone.callHistory[i].Duration;
            }
        }
        myPhone.DeleteHistory(longestCallIndex);
        Console.WriteLine();
        Console.WriteLine("The total price of the calls is {0:f2}", myPhone.CalculateTotalPrice(0.37));

        //Clear history and print it.
        myPhone.ClearHistory();
        Console.WriteLine();
        if (myPhone.callHistory.Count > 0)
        {
            foreach (var item in myPhone.callHistory)
            {
                Console.WriteLine("Date and time: {0}, Dialed phone: {1}, Duration: {2} seconds", item.Time, item.DialedPhone, item.Duration);
                Console.WriteLine();
            }
        }
        else
        {
            Console.WriteLine("Empty");
        }

    }
    static void Main()
    {
        //Test task 4
        GSM iPhone = new GSM("iPhone4s", "Apple");

        //Console.WriteLine(iPhone.ToString());

        //Task 7
        GSM[] phoneStore = new GSM[]
        {
            new GSM("N95", "Nokia", 123, "nobody", new Battery("1200", 105, 43), new Display(8d, 16000000)),
            new GSM("X200", "Samsung"),
            new GSM("eXperia", "Sony", 500)
        };

        //Sell a phone to Bai Pesho
        phoneStore[0].Owner = "Bai Pesho";

        // Console.WriteLine("Phones in Store:");
        foreach (var phone in phoneStore)
        {
            //Console.WriteLine(phone);
        }

        //Console.WriteLine(GSM.IPhone4S);

        GSM workPhone = new GSM("210", "Huavei", 5, "worker");

        workPhone.MakeCall(883555555, 150);
        workPhone.MakeCall(883556555, 190);
        workPhone.MakeCall(883566645, 212);

        foreach (var call in workPhone.CallHistory)
        {
            Console.WriteLine("Call to {0},  duration: {1}", call.PhoneNumber, call.CallDuration);
        }

        //Print Total Cost
        Console.WriteLine("Total Cost: " + workPhone.CalculateTotalPrice(0.37m));

        //Find and remove longest call
        ;
        ulong maxDuration = ulong.MinValue;

        foreach (var call in workPhone.CallHistory)
        {
            if (call.CallDuration > maxDuration)
            {
                maxDuration = call.CallDuration;
            }
        }

        if (maxDuration != ulong.MinValue)
        {
            workPhone.RemoveCallByDuration(maxDuration);
            Console.WriteLine();
            Console.WriteLine("Removed call with duration: " + maxDuration);
        }

        //Print Total Cost without longest duration

        Console.WriteLine("Total Cost: " + workPhone.CalculateTotalPrice(0.37m));
        Console.WriteLine();

        foreach (var call in workPhone.CallHistory)
        {
            Console.WriteLine(call.ToString());
        }

        workPhone.ClearCallHistory();
        //Print again
        Console.WriteLine("Call History: ");
        foreach (var call in workPhone.CallHistory)
        {
            Console.WriteLine(call.ToString());
        }
        //
    }
Esempio n. 10
0
    public static void Main()
    {
        //Creating the instance of GSM.
        Battery litiumBattery = new Battery("Normal", 123, 20.5, BatteryType.LiIon);
        Display big           = new Display(8.4, 3000);
        GSM     myPhone       = new GSM("W595", "Sony - Erikson", 678, "Cecilia", litiumBattery, big);

        //Adding few calls.
        Call[] calls = new Call[4];
        calls[0] = new Call(DateTime.Today, DateTime.Now, "0888123456", 123);
        calls[1] = new Call(DateTime.Today, DateTime.Now, "0877123456", 45);
        calls[2] = new Call(DateTime.Today, DateTime.Now, "0899123456", 540);
        calls[3] = new Call(DateTime.Today, DateTime.Now, "0789123456", 18);
        for (int i = 0; i < calls.Length; i++)
        {
            myPhone.AddHistory(calls[i]);
        }

        //Display calls information.
        foreach (var item in myPhone.callHistory)
        {
            Console.WriteLine("Date and time: {0}, Dialed phone: {1}, Duration: {2} seconds", item.Time, item.DialedPhone, item.Duration);
            Console.WriteLine();
        }

        //Print total price.
        Console.WriteLine();
        Console.WriteLine("The total price of the calls is {0:f2}", myPhone.CalculateTotalPrice(0.37));

        //Remove longest call and calculate price again.
        int    longestCallIndex = 0;
        double longestDuration  = 0.0;

        for (int i = 0; i < myPhone.callHistory.Count; i++)
        {
            if (myPhone.callHistory[i].Duration > longestDuration)
            {
                longestCallIndex = i;
                longestDuration  = myPhone.callHistory[i].Duration;
            }
        }
        myPhone.DeleteHistory(longestCallIndex);
        Console.WriteLine();
        Console.WriteLine("The total price of the calls is {0:f2}", myPhone.CalculateTotalPrice(0.37));

        //Clear history and print it.
        myPhone.ClearHistory();
        Console.WriteLine();
        if (myPhone.callHistory.Count > 0)
        {
            foreach (var item in myPhone.callHistory)
            {
                Console.WriteLine("Date and time: {0}, Dialed phone: {1}, Duration: {2} seconds", item.Time, item.DialedPhone, item.Duration);
                Console.WriteLine();
            }
        }
        else
        {
            Console.WriteLine("Empty");
        }
    }
    static void Main()
    {
        //Test task 4
        GSM iPhone = new GSM("iPhone4s", "Apple");

        //Console.WriteLine(iPhone.ToString());

        //Task 7
        GSM[] phoneStore = new GSM[]
        {
            new GSM("N95","Nokia",123, "nobody", new Battery("1200",105,43), new Display(8d,16000000)),
            new GSM("X200","Samsung"),
            new GSM("eXperia","Sony",500)
        };

        //Sell a phone to Bai Pesho
        phoneStore[0].Owner = "Bai Pesho";

           // Console.WriteLine("Phones in Store:");
        foreach (var phone in phoneStore)
        {
            //Console.WriteLine(phone);
        }

        //Console.WriteLine(GSM.IPhone4S);

        GSM workPhone = new GSM("210", "Huavei", 5, "worker");
        workPhone.MakeCall(883555555, 150);
        workPhone.MakeCall(883556555, 190);
        workPhone.MakeCall(883566645, 212);

        foreach (var call in workPhone.CallHistory)
        {
            Console.WriteLine("Call to {0},  duration: {1}",call.PhoneNumber,call.CallDuration);
        }

        //Print Total Cost
        Console.WriteLine("Total Cost: " + workPhone.CalculateTotalPrice(0.37m));

        //Find and remove longest call
        ;
        ulong maxDuration = ulong.MinValue;

        foreach (var call in workPhone.CallHistory)
        {
            if (call.CallDuration>maxDuration)
            {
                maxDuration = call.CallDuration;
            }
        }

        if (maxDuration != ulong.MinValue)
        {
            workPhone.RemoveCallByDuration(maxDuration);
            Console.WriteLine();
            Console.WriteLine("Removed call with duration: " + maxDuration);
        }

        //Print Total Cost without longest duration

        Console.WriteLine("Total Cost: " + workPhone.CalculateTotalPrice(0.37m));
        Console.WriteLine();

        foreach (var call in workPhone.CallHistory)
        {
            Console.WriteLine(call.ToString());
        }

        workPhone.ClearCallHistory();
        //Print again
        Console.WriteLine("Call History: ");
        foreach (var call in workPhone.CallHistory)
        {
            Console.WriteLine(call.ToString());
        }
        //
    }