Esempio n. 1
0
 static void Main(string[] args)
 {
     Bank first = new Bank();
     Account ein = new Account(0, 0000,100);
     Account one = new Account(1, 1111, 100);
     first.accounts.Add(ein);
     first.accounts.Add(one);
     first.CreateAccount(2222, 20000);
     //this tests that creataccount adds the account properly to accounts
     for (int x = 0; x < first.accounts.Count; x++)
         Console.WriteLine(first.accounts[x].accountNum);
     Console.ReadLine();
     //tests basic functions
     one.Deposit(1000);
     one.Deposit(1000);
     one.Withdraw(300);
     one.Deposit(1000);
     one.Withdraw(900);
     one.Deposit(10000);
     one.Withdraw(9998000);
     one.Deposit(1000);
     one.Withdraw(300);
     Console.ReadLine();
     // ATM test
     Atm zero = new Atm();
     zero.ExecuteInput(first);
     zero.ExecuteInput(first);
     zero.ExecuteInput(first);
     Console.ReadLine();
 }
Esempio n. 2
0
 public void CreateAccount(int pin , int balance)
 {
     int accountNumber = (accounts.Count);
     Account a = new Account(accountNumber, pin, balance);
     accounts.Add(a);
     Console.WriteLine("Account " + ("" + accountNumber) + " created with starting balance " + ("" + (balance)));
 }
Esempio n. 3
0
 /* ****************************************************************************************
  * Add the given Account to the given AccountList
  * Assumption - There is room for the Account
  */
 public static void AddAccountToAccountList(ref AccountList theList, Account theAccount)
 {
     theList.theAccounts[theList.numberOfAccounts] = theAccount;
     theList.numberOfAccounts++;
 }
Esempio n. 4
0
 public static void WriteAccountToFile(Account theAccount)
 {
     try
     {
         using (StreamWriter writer = new StreamWriter(FILE_PATH, true))
         {
             writer.WriteLine(theAccount.name);
             writer.WriteLine(theAccount.number);
             writer.WriteLine(theAccount.balance);
             writer.WriteLine(theAccount.password);
         }
     }
     catch (IOException)
     {
         Console.WriteLine("Failed to create / modify the file. Do you have permissions?");
     }
 }
Esempio n. 5
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;

            }
        }