Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            //SavingsAccount s1 = new SavingsAccount(50);
            //SavingsAccount s2 = new SavingsAccount(100);
            //SavingsAccount s3 = new SavingsAccount(10000.75);

            //Console.WriteLine("Account balance for s1: {0}, interest rate {1}", s1.currBalance, SavingsAccount.currInterestRate);
            //Console.WriteLine("Account balance for s2: {0}, interest rate {1}", s2.currBalance, SavingsAccount.currInterestRate);
            //Console.WriteLine("Account balance for s3: {0}, interest rate {1}", s3.currBalance, SavingsAccount.currInterestRate);

            SavingsAccount s1 = new SavingsAccount(50);

            //  Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            //  Try to change the interest rate.
            SavingsAccount.SetInterestRate(0.08);
            //  Make a second account.
            SavingsAccount s2 = new SavingsAccount(100);

            //  Should print 0.08...right?
            //  Using static constructor
            //  Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            //  Make new object, this does NOT 'reset' the interest rate.
            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            SavingsAccount s1 = new SavingsAccount(50);
            SavingsAccount s2 = new SavingsAccount(100);

            // Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Make new object, this does NOT 'reset' the interest rate.
            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            Console.WriteLine();
            Console.WriteLine("***** Fun with Static Classes *****\n");

            // This is just fine.
            TimeUtilClass.PrintDate();
            TimeUtilClass.PrintTime();

            // Compiler error! Can't create instance of static classes!
            //TimeUtilClass u = new TimeUtilClass ();

            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            SavingsAccount s1 = new SavingsAccount(50);

            // Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Try to change the interest rate via property.
            SavingsAccount.SetInterestRate(0.08);

            // Make a second account.
            SavingsAccount s2 = new SavingsAccount(100);

            // Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Make new object, this does NOT 'reset' the interest rate.
            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Print the current interest rate via property.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.InterestRate);

            Console.ReadLine();
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Simple Saving Account Class");

            //three instances of SavingAccount

            SavingsAccount s1 = new SavingsAccount(50);

            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");


            /**
             *  The static data is shared by all objects of same
             *  category meaning .. currInterestRate is same for
             *  all savingAccount s1,s2 and s3 or any other created
             */

            //pring the current InterestRate
            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");
            SavingsAccount.SetInterestRate(0.8);

            SavingsAccount s4 = new SavingsAccount(10000.75);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");
            SavingsAccount s2 = new SavingsAccount(100);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");


            // Calling Static Class
            TimeUtilClass.PrintDate();
            TimeUtilClass.PrintTime();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");

            Console.WriteLine($"Before account set up, Interest Rate is {SavingsAccount.GetInterestRate()}");
            SavingsAccount[] accounts = new SavingsAccount[3];

            accounts[0] = new SavingsAccount(50);
            accounts[1] = new SavingsAccount(100);

            // Print the current interest rate.
            Console.WriteLine("2 accounts set up, Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Make new object, this does NOT 'reset' the interest rate.
            accounts[2] = new SavingsAccount(10000.75);
            Console.WriteLine("3 new accounts, Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            SavingsAccount.InterestRate = .05;
            Console.WriteLine("Interest Rate is now: {0}", SavingsAccount.InterestRate);

            for (int i = 0; i < accounts.Length; i++)
            {
                Console.WriteLine("Balance for account {1} is {0}, interest rate is {2}",
                                  accounts[i].currentBalance, i, SavingsAccount.GetInterestRate());
            }

            Console.ReadLine();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            // Исполняющая система вызывает статический конструктор всего один раз для этого экземпляра приложения
            // когда создает первый раз экземпляр класса
            // или перед первым обращением к статическому члену этого класса
            // (даже до того момента когда будет дана команда создать первый экземпляр класса)
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Создать счет
            SavingsAccount s1 = new SavingsAccount(50);

            // Вывести текущую процентную ставку
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // изменение процентной ставки
            SavingsAccount.SetInterestRate(0.08);

            // Создать второй счет
            SavingsAccount s2 = new SavingsAccount(100);

            // Вывести текущую процентную ставку
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            Console.ReadLine();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun whith Static Data *****\n");
            SavingsAccount s1 = new SavingsAccount(50);
            SavingsAccount s2 = new SavingsAccount(100);

            Console.WriteLine("Inerest Rate is: {0}", SavingsAccount.GetInterestRate());
            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine("Inerest Rate is: {0}", SavingsAccount.GetInterestRate());
            Console.ReadLine();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with static data ****");
            SavingsAccount s1 = new SavingsAccount(10);
            SavingsAccount s2 = new SavingsAccount(1000);

            Console.WriteLine("Interest rate is {0}\n", SavingsAccount.GetInterestRate());

            SavingsAccount.SetInterestRate(0.08);
            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine("Interest rate is {0}\n", SavingsAccount.GetInterestRate());
            Console.ReadLine();
        }
Exemplo n.º 9
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            var s1 = new SavingsAccount(50);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            SavingsAccount.SetInterestRate(0.08);
            var s2 = new SavingsAccount(100);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.InterestRate);

            Console.ReadLine();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            // Make an account.
            SavingsAccount s1 = new SavingsAccount(50);

            // Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            // Try to change the interest rate via property.
            SavingsAccount.SetInterestRate(0.08);
            // Make a second account.
            SavingsAccount s2 = new SavingsAccount(100);

            // Should print 0.08...right??
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            Console.ReadLine();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            //Создать счет.
            SavingsAccount s1 = new SavingsAccount(50);

            //Вывести текущую процентную ставку.
            Console.WriteLine("Interest Rate is {0}", SavingsAccount.GetInterestRate());

            // Попытаться изменить процентную ставку через свойство.
            SavingsAccount.SetInterestRate(0.08);

            //Создать второй счет.
            SavingsAccount s2 = new SavingsAccount(100);

            // Должен вывести 0.08.... не так ли??
            //Создать новый объект; это не сбросить процентную ставку.
            //SavingsAccount s3 = new SavingsAccount(10000.75);
            Console.WriteLine("Interest Rate is {0}", SavingsAccount.GetInterestRate());
            Console.ReadLine();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Static data member with objects practice");

            // Instantiate object.
            SavingsAccount s1 = new SavingsAccount(50);

            // Print the current interest rate.
            Console.WriteLine("Interest rate is: {0}", SavingsAccount.GetInterestRate());

            // Try to change the interest rate via property.
            SavingsAccount.SetInterestRate(0.08);

            // Proves change worked.
            Console.WriteLine("Interest rate is: {0}", SavingsAccount.GetInterestRate());

            // When new object is made it resets interest rate.
            SavingsAccount s2 = new SavingsAccount(100);

            Console.WriteLine("Interest rate is: {0}", SavingsAccount.GetInterestRate());

            Console.ReadLine();
        }