Beispiel #1
0
        static void Main(string[] args)
        {
            var account = new Account("Simion Marius");

            account.MakeDeposit(1000M, "Deposit creation");
            account.Withdrawal(200M, "Rent payment");
            account.MakeDeposit(1500M, "Salary");
            account.Withdrawal(2000M, "Products bought");     // should give an Insuficient funds error.
            account.AccountStatement();

            account.CloseAccount();

            account.MakeDeposit(1500M, "Closing test");       // should give an Account closed error.
            account.AccountStatement();



            var account1 = new Account("Simion Elena");

            account1.AccountStatement();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Account account = new Account("Onescu Oana Florentina", 10000);

            Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} initial balance.");
            account.MakeWithdrawal(500, DateTime.Now, "Rent payment");
            Console.WriteLine(account.Balance);
            account.MakeDeposit(100, DateTime.Now, "Friend paid me back");
            Console.WriteLine(account.Balance);

            Console.WriteLine(account.CloseAccount());

            Console.WriteLine(account.GetAccountHistory());
        }
Beispiel #3
0
        public static void MenuS(Account SA)
        {
            string optionS;

            Regex Rgx = new Regex(@"\d+\.\d+");

            do
            {
                Console.WriteLine("You accessed the Savings page:");

                Console.WriteLine(String.Format("A. Deposit\nB. Withdraw\nC. Close + Report\nR. Go Back"));
                optionS = Console.ReadLine().ToUpper();

                switch (optionS)
                {
                case "A":
                    Console.WriteLine("Enter the amount you want to deposit:");
                    string stringAmountD = Console.ReadLine();
                    if (!(Rgx.IsMatch(stringAmountD)))
                    {
                        throw new FormatException("The number you entered is not acceptable");
                    }
                    double.TryParse(stringAmountD, out double userAmountD);
                    SA.MakeDeposit(userAmountD);
                    break;

                case "B":
                    Console.WriteLine("Enter the amount you want to withdraw:");
                    string stringAmountW = Console.ReadLine();
                    if (!(Rgx.IsMatch(stringAmountW)))
                    {
                        throw new FormatException("The number you entered is not acceptable");
                    }
                    double.TryParse(stringAmountW, out double userAmountW);
                    SA.MakeWithdrawl(userAmountW);
                    break;

                case "C":
                    Console.WriteLine(SA.CloseAndReport());
                    Console.WriteLine("The values yield a change of: {0:F2}%", SA.GetPercentageChange());
                    break;

                case "R":
                    break;

                default:
                    throw new InvalidOperationException("That's not what I'm looking for...");
                }
            }while (optionS != "R");
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var account = new Account("David", 5000, 13);

            Console.WriteLine($"Account {account.AccountNumber} was created for {account.Owner} with {account.Balance} balance.");

            account.MakeWithdrawal(500, DateTime.Now, "Rent payment");

            account.MakeDeposit(100, DateTime.Now, "friend paid me back");


            account.AddInterests(0.10, DateTime.Now, "rate is increese 10");

            Console.WriteLine(account.AccountHistory());

            // Test exceptions
            try
            {
                var invalidAccount = new Account("invalid", -80, 12);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine("Exception caught creating account with negative balance");
                Console.WriteLine(e.ToString());
            }

            // Test for a negative balance
            try
            {
                account.MakeWithdrawal(750, DateTime.Now, "Attempt to overdraw");
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine("Exception caught trying to overdraw");
                Console.WriteLine(e.ToString());
            }

            try
            {
                account.AddInterests(23, DateTime.Now, "Interest rate is out of range!");
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine("Exception caught using high rate");
                Console.WriteLine(e.ToString());
            }

            Console.ReadLine();
        }