コード例 #1
0
        static string calculateYearOfWarrantyExpirationForMobilePhone(MobilePhone mobilePhone, int warrantyInMonths, string inputYear)
        {
            DateTime warrantyExpirationYear = new DateTime();

            switch (warrantyInMonths)
            {
            case 12:
            {
                warrantyExpirationYear = mobilePhone.DatePurchased.AddYears(1);
                inputYear = warrantyExpirationYear.Year.ToString();
                return(inputYear);
            }

            case 24:
            {
                warrantyExpirationYear = mobilePhone.DatePurchased.AddYears(2);
                inputYear = warrantyExpirationYear.Year.ToString();
                return(inputYear);
            }

            case 60:
            {
                warrantyExpirationYear = mobilePhone.DatePurchased.AddYears(5);
                inputYear = warrantyExpirationYear.Year.ToString();
                return(inputYear);
            }
            }
            return("1");
        }
コード例 #2
0
        static List <MobilePhone> PreliminaryInputPhones()
        {
            var listOfPhones = new List <MobilePhone>();
            var tempPhone    = new MobilePhone(Guid.NewGuid(), "Old", new DateTime(2011, 11, 1).Date, 0, 1000, MobilePhone.PhoneCompanies.Apple, true, "099434553", "Someone");

            listOfPhones.Add(tempPhone);
            tempPhone = new MobilePhone(Guid.NewGuid(), "A iphone X ( boss's phone)", new DateTime(2010, 10, 2).Date, 0, 1000, MobilePhone.PhoneCompanies.Samsung, true, "091324532", "Spiderman");
            listOfPhones.Add(tempPhone);
            tempPhone = new MobilePhone(Guid.NewGuid(), "Barely working", new DateTime(2014, 5, 1).Date, 0, 800, MobilePhone.PhoneCompanies.Sony, false, "099856432", "Jameson");
            listOfPhones.Add(tempPhone);
            tempPhone = new MobilePhone(Guid.NewGuid(), "Bad touchscreen", new DateTime(2000, 2, 2).Date, 0, 400, MobilePhone.PhoneCompanies.Samsung, false, "097421234", "BATMAN");
            listOfPhones.Add(tempPhone);
            return(listOfPhones);
        }
コード例 #3
0
        public MobilePhone AddMobilePhone()
        {
            var success     = false;
            var description = "";
            var warranty    = 0;
            var price       = 0.0;
            var seller      = PhoneCompanies.Apple;
            var phoneNumber = "";
            var owner       = "";

            Console.WriteLine("Enter a description");
            description = Console.ReadLine();

            do
            {
                Console.WriteLine("Enter the warranty in number of months");
                var number = Console.ReadLine();
                success = int.TryParse(number, out warranty);
                if (!success)
                {
                    Console.WriteLine("Wrong entry, try again");
                }
            } while (!success);

            do
            {
                Console.WriteLine("Enter a price");
                var number = Console.ReadLine();
                success = double.TryParse(number, out price);
                if (!success)
                {
                    Console.WriteLine("Wrong entry, try again");
                }
            } while (!success);

            do
            {
                success = false;
                Console.WriteLine("Enter a seller out of the listed");
                var values = Enum.GetValues(typeof(PhoneCompanies));
                foreach (var v in values)
                {
                    Console.WriteLine(v);
                }
                var input = Console.ReadLine();
                foreach (var v in values)
                {
                    if (input.ToLower() == v.ToString().ToLower())
                    {
                        success = true;
                        seller  = (PhoneCompanies)v;
                    }
                }
            } while (!success);

            var year  = 0;
            var month = 0;
            var day   = 0;

            do
            {
                Console.WriteLine("Enter the year it was bought in number");
                var number = Console.ReadLine();
                success = int.TryParse(number, out year);
                if (!success)
                {
                    Console.WriteLine("Wrong entry, try again");
                }
            } while (!success);
            do
            {
                Console.WriteLine("Enter the month it was bought in number");
                var number = Console.ReadLine();
                success = int.TryParse(number, out month);
                if (!success)
                {
                    Console.WriteLine("Wrong entry, try again");
                }
            } while (!success || month < 1 || month > 12);
            do
            {
                Console.WriteLine("Enter the day it was bought in number");
                var number = Console.ReadLine();
                success = int.TryParse(number, out day);
                if (!success)
                {
                    Console.WriteLine("Wrong entry, try again");
                }
            } while (!success || day > 30 || day < 1);

            var time = new DateTime(year, month, day).Date;

            bool battery;

            do
            {
                Console.WriteLine("Write 'true' if you computer has a battery or 'false' if it doesn't");
                var text = Console.ReadLine();
                success = bool.TryParse(text, out battery);
            } while (!success);

            Console.WriteLine("Enter your phone number");
            phoneNumber = Console.ReadLine();
            Console.WriteLine("Write the owners first and last name at once");
            owner = Console.ReadLine();

            var phon = new MobilePhone(Guid.NewGuid(), description, time, warranty, price, seller, battery, phoneNumber, owner);

            return(phon);
        }