static void Main(string[] args) { var account = new BankAccount("Patrick", 1000); Console.WriteLine($"Account Created:\n\tAccount Number: {account.Number}\n\tAccount Holder: {account.Owner}\n\tAccount Balance: ${account.Balance:N2}"); 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.Write(account.GetAccountHistory()); //try //{ // account.MakeWithdrawal(750, DateTime.Now, "Attempt to overdraw"); //} //catch (InvalidOperationException e) //{ // Console.WriteLine("Exception caught trying to overdraw"); // Console.WriteLine(e.ToString()); //} //try //{ // var invalidAccount = new BankAccount("invalid", -55); //} //catch (ArgumentOutOfRangeException e) //{ // Console.WriteLine("Exception caught creating account with negative balance"); // Console.WriteLine(e.ToString()); //} }
static void Main(string[] args) { var account = new BankAccount("Godwin", 1000); Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} initialBalance."); 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("Hello World!"); // 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()); } Console.WriteLine(account.GetAccountHistory()); }
static void Main(string[] args) { var account = new BankAccount("Mert", 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); Console.WriteLine(account.GetAccountHistory()); }
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("Nevil", 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 that the initial balances must be positive try { var invalidAccount = new BankAccount("invalid", -55); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Exception caught creating acount with negative balance"); Console.WriteLine(e.ToString()); } // Test for a negative balance. try { account.MakeWithdrawal(1750, DateTime.Now, "Attempting to overdraw"); } catch (InvalidOperationException e) { Console.WriteLine("Exception caught trying to overdraw"); Console.WriteLine(e.ToString()); } Console.WriteLine(account.GetAccountHistory()); var giftCard = new GiftCardAccount("gift card", 100, 50); giftCard.MakeWithdrawal(20, DateTime.Now, "get expensive coffee"); giftCard.MakeWithdrawal(50, DateTime.Now, "buy groceries"); giftCard.performMonthEndTransactions(); // can make additional deposits giftCard.MakeDeposit(27.50m, DateTime.Now, "add some additional spending money"); Console.WriteLine(giftCard.GetAccountHistory()); var savings = new InterestEarningAccount("saving account", 1000); savings.MakeDeposit(750, DateTime.Now, "save some money"); savings.MakeDeposit(1250, DateTime.Now, "Add more savings"); savings.MakeWithdrawal(250, DateTime.Now, "Needed to pay monthly bills"); savings.performMonthEndTransactions(); Console.WriteLine(savings.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("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()); }
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) { 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; } } } }