static void Main(string[] args) { var akount1 = new BankAccount("Ahsan", 10000); Console.WriteLine($"Account {akount1.Number} was created for {akount1.Owner} with {akount1.Balance}"); akount1.MakeWithdrawal(1230, DateTime.Now, "Rent Payment"); Console.WriteLine(akount1.Balance); akount1.MakeDeposit(3430, DateTime.Now, "Paycheck #21"); Console.WriteLine(akount1.Balance); Console.WriteLine(akount1.GetAccountHistory()); //SomeTests(); }
static void Main(string[] args) { var account = new BankAccount("Ana", 11120); Console.WriteLine($"account {account.Number} created for {account.Owner} with {account.Balance} amount"); account.MakeWithdrawal(500, DateTime.Now, "Rent payment"); Console.WriteLine(account.Balance); account.MakeDeposit(100, DateTime.Now, "Friend paid me back"); Console.WriteLine(account.Balance); // "Try and catch" to test that the initial balances must be positive. try { var invalidAccount = new BankAccount("invalid", -55); } 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()); } 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.GetAccountHistory()); }
static void Main(string[] args) { // Create a new account var account = new BankAccount("Nick Davies", 2500); Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} opening balance."); // Try to create an account with negative opening balance try { var invalidAccount = new BankAccount("invalid", -55); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Exception caught creating account with negative balance."); Console.WriteLine(e.ToString()); } // Make a withdrawal account.MakeWithdrawal(500, DateTime.Now, "Rent Payment"); Console.WriteLine($"Balance: {account.Balance}"); // Make a deposit account.MakeDeposit(2000, DateTime.Now, "Salary"); Console.WriteLine($"Balance: {account.Balance}"); // Try to make a withdrawal over the available balance try { account.MakeWithdrawal(7500, DateTime.Now, "Fraud"); } catch (InvalidOperationException e) { Console.WriteLine("Exception caught trying to overdaw."); Console.WriteLine(e.ToString()); } Console.WriteLine(account.GetAccountHistory()); }
static void Main(string[] args) { var account = new BankAccount("Matty", 1000); 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); // Test for a negative balance try { account.MakeWithdrawal(750, DateTime.Now, "Attempt to overdraw"); } catch { Console.WriteLine("Withdrawal not allowed. Will overdraft."); } Console.WriteLine(); Console.WriteLine(account.GetAccountHistory()); }
static void Main(string[] args) { var account = new BankAccount("Victor", 10000); Console.WriteLine($"Account {account.Number} was created for {account.Owner} with initial balance:" + $"{account.Balance}"); account.MakeWithdrawal(500, DateTime.Now, "Shopping"); Console.WriteLine($"New account balance is {account.Balance}"); account.MakeDeposit(7000, DateTime.Now, "Friend paid loan back"); Console.WriteLine($"New account balance is {account.Balance}"); // Test that the initial balances must be positive. try { var invalidAccount = new BankAccount("invalid", -55); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Exception caught creating account with negative balance"); Console.WriteLine(e.ToString()); } // Test that withdrawal amount is does not cause -ve account Balance try { var validAccount = new BankAccount("valid", 1000); validAccount.MakeWithdrawal(2000, DateTime.Now, "Emergency withdrawal"); } catch (InvalidOperationException e) { Console.WriteLine("Exception caught withdrawing and account with amount larger than Balance"); Console.WriteLine(e.ToString()); } Console.WriteLine(account.GetAccountHistory()); }
public static void SomeTests() { // Test that the initial balances must be positive. try { var invalidAkount1 = new BankAccount("Bill", -55); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Cannot make an account with negative balance"); Console.WriteLine(e); } // Test for a negative balance. try { var testAccount1 = new BankAccount("person1", 1000); testAccount1.MakeWithdrawal(1222333, DateTime.Now, "Ateempt to overdraw"); } catch (InvalidOperationException e) { Console.WriteLine("Exception caught trying to overdraw"); Console.WriteLine(e); } }
static void Main(string[] args) { using (var db = new Records()) { bool start = true; while (start == true) { Console.WriteLine("Jeśli chcesz założyć konto - wpisz: new"); Console.WriteLine("Jeśli chcesz zobaczyć stan kont - wpisz: list"); Console.WriteLine("Jeśli chcesz zasilić konto - wpisz: op"); Console.WriteLine("Jeśli chcesz wypłacić pieniądze - wpisz: wyp"); Console.WriteLine("Jeśli chcesz zakończyć - wpisz: end"); string decisionA = Console.ReadLine(); if (decisionA == "new") { Console.WriteLine("Podaj dane właściciela konta"); string imie = Console.ReadLine(); Console.WriteLine("Podaj kwotę wpłaty."); string kwota = Console.ReadLine(); int kwotaInt = Convert.ToInt32(kwota); var pieniadze = db.AccountData; pieniadze.Add( new Info { Owner = imie, Money = kwotaInt } ); db.SaveChanges(); var account = new BankAccount(imie, kwotaInt); Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} initial balance."); } // account.MakeWithdrawal(500, DateTime.Now, "Rent payment"); //Console.WriteLine($"New account balance is {account.Balance}."); //account.MakeDeposit(100, DateTime.Now, "Friend paid me back"); //Console.WriteLine($"New account balance is {account.Balance}."); // Console.WriteLine(account.GetAccountHistory()); if (decisionA == "list") { var listakont = db.AccountData.ToList(); Console.WriteLine($"|{"Właściciel",-15}|{"Stan",8}|"); Console.WriteLine("==========================="); foreach (var n in listakont) { Console.WriteLine($"|{n.Owner,-15}|{n.Money,8}|"); } } if (decisionA == "op") { var listakont = db.AccountData.ToList(); Console.WriteLine($"|{"Id",-3}|{"Właściciel",-15}|{"Stan",8}|"); Console.WriteLine("=============================="); foreach (var n in listakont) { Console.WriteLine($"|{n.InfoId,-3}|{n.Owner,-15}|{n.Money,8}|"); } Console.WriteLine("Wpisz Id konta"); string User = Console.ReadLine(); int UserInt = Convert.ToInt32(User); var SingleAccount = db.AccountData .Single(b => b.InfoId == UserInt); var account = new BankAccount(SingleAccount.Owner, SingleAccount.Money); Console.WriteLine("Podaj kwotę którą chcesz zasilić konto:"); string kwota = Console.ReadLine(); int kwotaInt = Convert.ToInt32(kwota); Console.WriteLine("Podaj tytuł wpłaty:"); string wplataTyt = Console.ReadLine(); SingleAccount.Money = SingleAccount.Money + kwotaInt; db.SaveChanges(); var kwotaDec = Convert.ToDecimal(kwotaInt); account.MakeDeposit(kwotaDec, DateTime.Now, wplataTyt); Console.WriteLine($"Stan konta po wpłacie - {account.Balance}"); Console.WriteLine(account.GetAccountHistory()); var OperacjaHistoria = db.AccountHistory; OperacjaHistoria.Add( new Historia { Kwota = kwotaInt, Data = DateTime.Now, Notatki = wplataTyt } ); db.SaveChanges(); } if (decisionA == "wyp") { var listakont = db.AccountData.ToList(); Console.WriteLine($"|{"Id",-3}|{"Właściciel",-15}|{"Stan",8}|"); Console.WriteLine("=============================="); foreach (var n in listakont) { Console.WriteLine($"|{n.InfoId,-3}|{n.Owner,-15}|{n.Money,8}|"); } Console.WriteLine("Wpisz Id konta"); string User = Console.ReadLine(); int UserInt = Convert.ToInt32(User); var SingleAccount = db.AccountData .Single(b => b.InfoId == UserInt); var account = new BankAccount(SingleAccount.Owner, SingleAccount.Money); Console.WriteLine("Podaj kwotę którą chcesz wyplacić:"); string kwota = Console.ReadLine(); int kwotaInt = Convert.ToInt32(kwota); Console.WriteLine("Podaj tytuł wypłaty"); string wyplataTyt = Console.ReadLine(); SingleAccount.Money = SingleAccount.Money - kwotaInt; db.SaveChanges(); var kwotaDec = Convert.ToDecimal(kwotaInt); account.MakeWithdrawal(kwotaDec, DateTime.Now, wyplataTyt); Console.WriteLine($"Stan konta po wypłacie - {account.Balance}"); Console.WriteLine(account.GetAccountHistory()); } if (decisionA == "end") { start = false; } } } }