Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the ATM!");

            while (programIsRunning)
            {
                var    getSavingsBalance     = new GetSavingsBalance();
                double SavingsAccountBalance = getSavingsBalance.GetBalance();
                Console.WriteLine($"Your savings account balance is {SavingsAccountBalance}");

                var    getCheckingBalance     = new GetCheckingBalance();
                double CheckingAccountBalance = getCheckingBalance.GetBalance();
                Console.WriteLine($"Your checking account balance is {CheckingAccountBalance}");

                Console.WriteLine("Would you like to make a (withdrawal), (deposit) or (transfer) between your accounts?");
                Console.WriteLine("You can also (view) your most recent transaction or (exit) the ATM.");
                var startTask = Console.ReadLine().ToLower();

                // ERROR HANDLING

                if (startTask == "withdrawal")
                {
                    Console.WriteLine("Do you want to withdraw from your (checking) or (savings) account?");
                    var accountSelection = Console.ReadLine().ToLower();

                    var    userWithdrawal = new Withdrawal();
                    double newAmount      = userWithdrawal.StartWithdrawal(accountSelection);

                    Console.WriteLine("Your new balance is " + newAmount);
                }
                else if (startTask == "deposit")
                {
                    Console.WriteLine("Do you want to deposit into your (checking) or (savings) account?");
                    var accountSelection = Console.ReadLine().ToLower();

                    var    userDeposit = new Deposit();
                    double newAmount   = userDeposit.StartDeposit(accountSelection);

                    Console.WriteLine("Your new balance is " + newAmount);
                }
                else if (startTask == "transfer")
                {
                    Console.WriteLine("Please select the transfer you would like to make:");
                    Console.WriteLine("(1.) Transfer from your checking account to your savings account");
                    Console.WriteLine("(2.) Transfer from your savings account to your checking account");

                    var selection = Console.ReadLine();

                    var userTransfer = new Transfer();
                    userTransfer.StartTransfer(selection);
                }
                else if (startTask == "view")
                {
                    Console.WriteLine("Do you want to view your (checking) or (savings) account?");
                    var accountSelection = Console.ReadLine().ToLower();

                    if (accountSelection == "checking")
                    {
                        var viewCheckingStatement = new CheckingAccount();
                        viewCheckingStatement.ViewStatement();
                    }
                    else
                    {
                        var viewSavingsStatement = new SavingsAccount();
                        viewSavingsStatement.ViewStatement();
                    }
                }
                else
                {
                    programIsRunning = false;
                }
            }
        }
        static void Main(string[] args)
        {
            bool            validInput;
            string          userInput;
            string          userInputAmount;
            decimal         amount;
            bool            validWithdraw;
            CheckingAccount myAccount = new CheckingAccount(100.0m);
            SavingsAccount  mySavings = new SavingsAccount();

            do
            {
                Console.Clear();
                Console.WriteLine("Greetings and how may I serve you?\n");
                myAccount.CheckBallance();
                mySavings.CheckBallance();
                Console.Write("\nDo you want to (D)eposite, (W)ithdraw, (T)ransfer or (Q)uit? ");
                userInput = Console.ReadLine();

                // deposite
                if (String.Equals(userInput.ToLower(), "d"))
                {
                    do
                    {
                        Console.Write("Deposite to: (C)hecking or (S)avings? or (E)xit? ");
                        userInput = Console.ReadLine();
                    } while (!String.Equals(userInput.ToLower(), "c") && !String.Equals(userInput.ToLower(), "s") &&
                             !String.Equals(userInput.ToLower(), "e"));
                    if (!String.Equals(userInput.ToLower(), "e"))
                    {
                        do
                        {
                            Console.Write("How many Credits do you want to deposite? or (E)xit? ");
                            userInputAmount = Console.ReadLine();
                            validInput      = Decimal.TryParse(userInputAmount, out amount);
                        } while (!validInput && !String.Equals(userInputAmount.ToLower(), "e"));

                        if (!String.Equals(userInputAmount.ToLower(), "e"))
                        {
                            if (String.Equals(userInput.ToLower(), "c"))
                            {
                                myAccount.Deposite(amount);
                            }
                            else if (String.Equals(userInput.ToLower(), "s"))
                            {
                                mySavings.Deposite(amount);
                            }
                        }
                    }
                }

                // withdraw
                if (String.Equals(userInput.ToLower(), "w"))
                {
                    do
                    {
                        Console.Write("Withdraw from: (C)hecking or (S)avings? or (E)xit? ");
                        userInput = Console.ReadLine();
                    } while (!String.Equals(userInput.ToLower(), "c") && !String.Equals(userInput.ToLower(), "s") &&
                             !String.Equals(userInput.ToLower(), "e"));
                    if (!String.Equals(userInput.ToLower(), "e"))
                    {
                        do
                        {
                            {
                                do
                                {
                                    Console.Write("How many Credits do you want to withdraw? ");
                                    userInputAmount = Console.ReadLine();
                                    validInput      = Decimal.TryParse(userInputAmount, out amount);
                                } while (!validInput && !String.Equals(userInputAmount.ToLower(), "e"));

                                validWithdraw = true;
                                if (!String.Equals(userInputAmount.ToLower(), "e"))
                                {
                                    if (String.Equals(userInput.ToLower(), "c"))
                                    {
                                        validWithdraw = myAccount.Withdraw(amount);
                                    }
                                    else if (String.Equals(userInput.ToLower(), "s"))
                                    {
                                        validWithdraw = mySavings.Withdraw(amount);
                                    }
                                }
                            }
                        } while (!validWithdraw);
                    }
                }

                //transfer
                if (String.Equals(userInput.ToLower(), "t"))
                {
                    do
                    {
                        Console.Write("Fransfer from: (C)hecking to Savings or (S)avings to Checkings? or (E)xit? ");
                        userInput = Console.ReadLine();
                    } while (!String.Equals(userInput.ToLower(), "c") && !String.Equals(userInput.ToLower(), "s") &&
                             !String.Equals(userInput.ToLower(), "e"));

                    if (!String.Equals(userInput.ToLower(), "e"))
                    {
                        do
                        {
                            do
                            {
                                Console.Write("How many Credits do you want to transfer? or (E)xit? ");
                                userInputAmount = Console.ReadLine();
                                validInput      = Decimal.TryParse(userInputAmount, out amount);
                            } while (!validInput && !String.Equals(userInputAmount.ToLower(), "e"));

                            validWithdraw = true;
                            if (!String.Equals(userInputAmount.ToLower(), "e"))
                            {
                                if (String.Equals(userInput.ToLower(), "c"))
                                {
                                    validWithdraw = myAccount.Withdraw(amount);
                                    if (validWithdraw)
                                    {
                                        mySavings.Deposite(amount);
                                    }
                                }
                                else if (String.Equals(userInput.ToLower(), "s"))
                                {
                                    validWithdraw = mySavings.Withdraw(amount);
                                    if (validWithdraw)
                                    {
                                        myAccount.Deposite(amount);
                                    }
                                }
                            }
                        } while (!validWithdraw);
                    }
                }
            } while (!String.Equals(userInput.ToLower(), "q"));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // initialise account
            CheckingAccount checkingCurrency = new CheckingAccount();
            SavingsAccount  savingsCurrency  = new SavingsAccount();

            // decalring objects and variables
            int            transactionCounter = 0;
            ConsoleKeyInfo choice             = new ConsoleKeyInfo();

            Console.WriteLine("Greetings and how may I serve you?");

            do
            {
                Console.WriteLine("");
                Console.WriteLine("Would you like to: (D)eposit, (W)ithdraw, (C)heck Balance, (T)ransfer, (Q)uit?");
                choice = Console.ReadKey();

                switch (choice.KeyChar)
                {
                case 'D':
                case 'd':
                    Console.WriteLine("");
                    Console.WriteLine("how many credits do you want to deposit?");
                    checkingCurrency.deposit(Convert.ToDecimal(Console.ReadLine()));
                    transactionCounter++;
                    break;

                case 'W':
                case 'w':
                    Console.WriteLine("");
                    Console.WriteLine("how many credits do you want to withdraw?");
                    checkingCurrency.withdraw(Convert.ToDecimal(Console.ReadLine()));
                    transactionCounter++;
                    break;

                case 'C':
                case 'c':
                    Console.WriteLine("");
                    Console.WriteLine($"Your checking account has {checkingCurrency.getBalance()} credits");
                    Console.WriteLine($"Your savings account has {savingsCurrency.getBalance()} credits");
                    transactionCounter++;
                    break;

                case 'T':
                case 't':
                    decimal creditsToMove;
                    Console.WriteLine("");
                    Console.WriteLine("Transfer from (1)Checking to Savings or (2)Savings to Checking?");
                    choice = Console.ReadKey();
                    switch (choice.KeyChar)
                    {
                    case '1':
                        Console.WriteLine("");
                        Console.WriteLine("How many credits do you want to transfer to Savings account?");
                        creditsToMove = (Convert.ToDecimal(Console.ReadLine()));
                        checkingCurrency.withdraw(creditsToMove);
                        savingsCurrency.deposit(creditsToMove);
                        transactionCounter++;
                        break;

                    case '2':
                        Console.WriteLine("");
                        Console.WriteLine("How many credits do you want to transfer to checking account?");
                        creditsToMove = (Convert.ToDecimal(Console.ReadLine()));
                        savingsCurrency.withdraw(creditsToMove);
                        checkingCurrency.deposit(creditsToMove);
                        transactionCounter++;
                        break;
                    }
                    break;
                }

                if (transactionCounter == 5) // applies interest rates after 5 transactions
                {
                    Console.WriteLine("");
                    Console.WriteLine("Interest calculated!");
                    Console.WriteLine($"Your current checking account balance is {checkingCurrency.getBalance()} credits");
                    Console.WriteLine($"Your current savings account balance is {savingsCurrency.getBalance()} credits");
                    savingsCurrency.applyInterestRate();
                    transactionCounter = 0;
                }
            } while (choice.KeyChar != 'q');

            //read out after quitting
            Console.WriteLine("");
            Console.WriteLine($"Your final checking account balance is {checkingCurrency.getBalance()} credits");
            Console.WriteLine($"Your final savings account balance is {savingsCurrency.getBalance()} credits");
            Console.WriteLine("Thank you for your business, goodbye!");
            Console.ReadKey();
        }
Esempio n. 4
0
        /// <summary>
        /// The row containing the alias and account number is splitted when ' '.
        /// SQL query gets all account details associated with the specific account.
        /// Creates an instance of an Account object.
        /// </summary>
        /// <param name="alias_accountNr">A string containing both the alias and the account number of the selected account</param>
        /// <returns>The Account containing all account details</returns>
        private Account GetAccount(string alias_accountNr)
        {
            string[] splittedLine = alias_accountNr.Split(' ');
            string accountNumber = splittedLine[1];

            string commandLine = $"SELECT Alias, Currency, Amount, AccountType From Account where AccountNR= '{accountNumber}'";

            List<string> accountDetails = myController.readSingleColumnFromSQL(commandLine);

            if (accountDetails == null)
            {
                //connection failed
                return null;
            }

            string alias = accountDetails[0];
            string currency = accountDetails[1];
            double balance = Convert.ToDouble(accountDetails[2]);
            string accountType = accountDetails[3];
            Account account;

            switch (accountType)
            {
                case "1":
                    double withDrawmoneyLeftToday = CalculateAmountLeftToday(accountNumber);
                    if (withDrawmoneyLeftToday == (-1))
                    {
                        //cant withdraw more than 500 a day
                        return null;
                    }

                    account = new SavingsAccount(accountType, alias, accountNumber, balance, currency, withDrawmoneyLeftToday);
                    return account;

                default:
                    account = new Account(accountType, alias, accountNumber, balance, currency);
                    return account;

            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            //Create a savingsaccount and checkingaccount

            SavingsAccount  savings  = new SavingsAccount(50, 5);
            CheckingAccount checking = new CheckingAccount(100);

            string depositInput;
            string withdrawInput;
            string transferInput;

            //Greet the user and ask what he wants to do

            Console.WriteLine("Hello! What would you like to do?");
            Console.WriteLine("(D)eposit, (W)ithdraw, (C)heck balance, (T)ransfer, (Q)uit");
            string input = Console.ReadLine().ToUpper();


            do
            {
                if (input != "D" && input != "W" && input != "C" && input != "T" && input != "Q")
                {
                    Console.WriteLine("Please enter a valid input. D, W, C, T or Q");
                    Console.WriteLine("(D)eposit, (W)ithdraw, (C)heck balance, (T)ransfer, (Q)uit");
                    input = Console.ReadLine().ToUpper();
                }
                else
                {
                    continue;
                }
            } while (input != "D" && input != "W" && input != "C" && input != "T" && input != "Q");

            //Logic for deposits
            if (input == "D")
            {
                do
                {
                    Console.WriteLine("Deposit to (1)Checking or (2)Savings?");
                    depositInput = Console.ReadLine();
                    if (depositInput == "1")
                    {
                        Console.WriteLine("How much do you want to deposit?");
                        decimal depositAmount = Convert.ToDecimal(Console.ReadLine());
                        checking.Deposit(depositAmount);
                        Console.WriteLine(depositAmount + " has been deposited to your checking account");

                        savings.PrintBalance();
                        checking.PrintBalance();
                    }
                    else if (depositInput == "2")
                    {
                        Console.WriteLine("How much do you want to deposit?");
                        decimal depositAmount = Convert.ToDecimal(Console.ReadLine());
                        savings.Deposit(depositAmount);
                        Console.WriteLine(depositAmount + " has been deposited to your savings account");

                        savings.PrintBalance();
                        checking.PrintBalance();
                    }
                    else
                    {
                        Console.WriteLine("Invalid input, please enter a 1 or 2");
                    }
                } while (depositInput != "1" && depositInput != "2");
            }

            //Logic for withdrawing
            else if (input == "W")
            {
                do
                {
                    Console.WriteLine("Withdraw from (1)Checking or (2)Savings?");
                    withdrawInput = Console.ReadLine();
                    if (withdrawInput == "1")
                    {
                        Console.WriteLine("How much do you want to withdraw?");
                        decimal withdrawAmount = Convert.ToDecimal(Console.ReadLine());
                        checking.Withdraw(withdrawAmount);
                        Console.WriteLine(withdrawAmount + " has been withdrawn from your checking account");

                        savings.PrintBalance();
                        checking.PrintBalance();
                    }
                    else if (withdrawInput == "2")
                    {
                        Console.WriteLine("How much do you want to withdraw?");
                        decimal withdrawAmount = Convert.ToDecimal(Console.ReadLine());
                        savings.Deposit(withdrawAmount);
                        Console.WriteLine(withdrawAmount + " has been withdrawn from your savings account");

                        savings.PrintBalance();
                        checking.PrintBalance();
                    }
                    else
                    {
                        Console.WriteLine("Invalid input, please enter a 1 or 2");
                    }
                } while (withdrawInput != "1" && withdrawInput != "2");
            }

            //Logic for checking the balance
            else if (input == "C")
            {
                savings.PrintBalance();
                checking.PrintBalance();
            }

            //Logic for transferring money from one account to another
            else if (input == "T")
            {
                do
                {
                    Console.WriteLine("Transfer from (1)Checking to Savings(1) or from (2)Savings to Checking(2)?");
                    transferInput = Console.ReadLine();
                    if (transferInput == "1")
                    {
                        Console.WriteLine("How much do you want to transfer from your checking account to your saving saccount?");
                        decimal transferAmount = Convert.ToDecimal(Console.ReadLine());
                        checking.Withdraw(transferAmount);
                        savings.Deposit(transferAmount);
                        Console.WriteLine(transferAmount + " has been transfered between your accounts");

                        savings.PrintBalance();
                        checking.PrintBalance();
                    }
                    else if (transferInput == "2")
                    {
                        Console.WriteLine("How much do you want to transfer from your savings account to your checking account?");
                        decimal transferAmount = Convert.ToDecimal(Console.ReadLine());
                        savings.Withdraw(transferAmount);
                        checking.Deposit(transferAmount);
                        Console.WriteLine(transferAmount + " has been transfered between your accounts");

                        savings.PrintBalance();
                        checking.PrintBalance();
                    }
                    else
                    {
                        Console.WriteLine("Invalid input, please enter a 1 or 2");
                    }
                } while (transferInput != "1" && transferInput != "2");
            }

            //Exiting the program
            else if (input == "Q")
            {
                Console.WriteLine("The balance of your checking account is " + checking.Balance());
                Console.WriteLine("The balance of your savings account is " + savings.Balance());
                Console.WriteLine("Thank you for your business. Goodbye!");
                Console.WriteLine("Press any button to close this window");
                Console.ReadKey();
            }
        }
Esempio n. 6
0
        public void StartTransfer(string selection)
        {
            var newSavingsBalance  = new SavingsAccount();
            var newCheckingBalance = new CheckingAccount();

            if (selection == "1")
            {
                var enterAmount = false;
                while (enterAmount == false)
                {
                    Console.WriteLine("How much would you like to transfer from your checking account to your savings account?");
                    var  response = Console.ReadLine();
                    int  amount;
                    bool result = Int32.TryParse(response, out amount);

                    if (result == true)
                    {
                        enterAmount = true;
                        var transactionType = "transfer";
                        newSavingsBalance.SavingsAccountBalance = newSavingsBalance.SavingsAccountBalance + amount;
                        newSavingsBalance.StoreNewTransaction(newSavingsBalance.SavingsAccountBalance);
                        newSavingsBalance.LogToStatement(newSavingsBalance.SavingsAccountBalance, amount, transactionType);

                        newCheckingBalance.CheckingAccountBalance = newCheckingBalance.CheckingAccountBalance - amount;
                        newCheckingBalance.StoreNewTransaction(newCheckingBalance.CheckingAccountBalance);
                        newCheckingBalance.LogToStatement(newCheckingBalance.CheckingAccountBalance, amount, transactionType);
                    }
                    else
                    {
                        Console.WriteLine("Sorry, you didn't enter a valid amount. Please try again.");
                    }
                }
            }

            else
            {
                var enterAmount = false;
                while (enterAmount == false)
                {
                    Console.WriteLine("How much would you like to transfer from your savings account to your checking account?");
                    var  response = Console.ReadLine();
                    int  amount;
                    bool result = Int32.TryParse(response, out amount);

                    if (result == true)
                    {
                        enterAmount = true;
                        var transactionType = "transfer";
                        newCheckingBalance.CheckingAccountBalance = newCheckingBalance.CheckingAccountBalance + amount;
                        newCheckingBalance.StoreNewTransaction(newCheckingBalance.CheckingAccountBalance);
                        newCheckingBalance.LogToStatement(newCheckingBalance.CheckingAccountBalance, amount, transactionType);

                        newSavingsBalance.SavingsAccountBalance = newSavingsBalance.SavingsAccountBalance - amount;
                        newSavingsBalance.StoreNewTransaction(newSavingsBalance.SavingsAccountBalance);
                        newSavingsBalance.LogToStatement(newSavingsBalance.SavingsAccountBalance, amount, transactionType);
                    }
                    else
                    {
                        Console.WriteLine("Sorry, you didn't enter a valid amount. Please try again.");
                    }
                }
            }
        }