static void Main(string[] args) { BankAccount b = new BankAccount(); BankAccount c = new BankAccount(); while (true) { Console.WriteLine(""); Console.WriteLine("Welcome To The C# Bank"); Console.WriteLine("--===Menu==--"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Create a Checking Account"); Console.WriteLine("2 - Create a Savings Account"); Console.WriteLine("3 - Withdraw"); Console.WriteLine("4 - Deposit"); Console.WriteLine("5 - Check Balance"); Console.Write("Please Choose an Option: "); string option; option = Console.ReadLine(); int selected = Convert.ToInt32(option); if (selected == 0) { Environment.Exit(0); } if (selected == 1) { Console.Write("Enter a New Account Number: "); string inputAcctNum = Console.ReadLine(); Console.Write("Enter Initial Balance: "); string inputBal = Console.ReadLine(); double bal = Convert.ToDouble(inputBal); c = new CheckingAccount(inputAcctNum, bal); } if (selected == 2) { Console.Write("Enter a New Account Number: "); string inputAcctNum = Console.ReadLine(); Console.Write("Enter Initial Balance: "); string inputBal = Console.ReadLine(); double bal = Convert.ToDouble(inputBal); b = new SavingsAccount(inputAcctNum, bal); } if (selected == 3) { Console.WriteLine("If you withdraw more than 5 times then you will be charged a $10 fee from the account withdrawn."); Console.WriteLine("Current amount of withdrawls: " + ((CheckingAccount)c).GetNoOfTransactions()); Console.Write("Enter an amount to be withdrawn (You may only withdraw from your Checking Account): "); string inputAmt = Console.ReadLine(); double amt = Convert.ToDouble(inputAmt); if (amt <= ((CheckingAccount)c).GetBalance()) { ((CheckingAccount)c).Withdraw(amt); } else { Console.WriteLine("Amount entered greater than balance."); } } if (selected == 4) { Console.WriteLine("--==Account Selection==--"); Console.WriteLine("1 - Checking"); Console.WriteLine("2 - Savings"); Console.Write("Select an account to modify: "); string secondary = Console.ReadLine(); int choice = Convert.ToInt32(secondary); if (choice == 1) { Console.Write("Enter an amount to deposit: "); string aa = Console.ReadLine(); double bb = Convert.ToDouble(aa); ((CheckingAccount)c).Deposit(bb); } if (choice == 2) { Console.Write("Enter an amount to deposit: "); string aa = Console.ReadLine(); double bb = Convert.ToDouble(aa); ((SavingsAccount)b).Deposit(bb); } } if (selected == 5) { Console.WriteLine("--==Account Selection==--"); Console.WriteLine("1 - Checking"); Console.WriteLine("2 - Savings"); Console.Write("Select an account to modify: "); string secondary = Console.ReadLine(); int choice = Convert.ToInt32(secondary); if (choice == 1) { Console.WriteLine("Current Balance of Checking Account: $" + ((CheckingAccount)c).GetBalance()); } if (choice == 2) { Console.WriteLine("Current Balance of Savings Account: $" + ((SavingsAccount)b).GetBalance()); } } } }
static void Main(string[] args)//void does not return a value { //initialize variables bool continueInput = true; double initialDeposit; double monthlyDeposit; string input; //blank list List <SavingsAccount> listAccounts = new List <SavingsAccount>();//should this be an array? >>> nope, just list of class objects //create new account(s) do { //set initial values initialDeposit = 0; monthlyDeposit = 0; Console.Write("Please enter new customer name: "); string inputName = Console.ReadLine(); string customerName = new CultureInfo("en-US").TextInfo.ToTitleCase(inputName); if (!string.IsNullOrEmpty(customerName))//if not null, create new account { //Console.WriteLine(customerName); //Initial Deposit Amount (min. $1,000.00) Console.Write("Please enter {0}'s initial deposit amount (or Enter for min. $1,000.00): $", customerName); input = Console.ReadLine(); if (input != "") { initialDeposit = Convert.ToDouble(input); if (initialDeposit < 1000) { Console.WriteLine(">>> ERROR: initial deposit must be at least $1,000."); Console.WriteLine(""); } } else { initialDeposit = 1000.0; } //Console.WriteLine("Initial Deposit of ${0} is variable type: {1}",initialDeposit, initialDeposit.GetType()); //Monthly Deposit Amount //minimum of $50.00 set as Console.Write("Please enter {0}'s monthly deposit amount (or Enter for min. $50.00): $", customerName); input = Console.ReadLine(); if (input != "") { monthlyDeposit = Convert.ToDouble(input); if (monthlyDeposit < 50) { Console.WriteLine(">>> ERROR: monthly deposits must be at least $50."); Console.WriteLine(""); } } else { monthlyDeposit = 50.0; } //Console.WriteLine("Monthly Deposit of ${0} is variable type: {1}", monthlyDeposit, monthlyDeposit.GetType()); if (initialDeposit >= 1000.0 && monthlyDeposit >= 50) { //get random number between 0 and 9999 int randomNumber = GetRandomNumber(0000, 9999); //create new SavingsAccount SavingsAccount newAccount = new SavingsAccount(customerName, initialDeposit, monthlyDeposit, randomNumber);//how do I create a unique variable name? >>> don't need one //add to list of accounts listAccounts.Add(newAccount);//how do I create a list of all accounts created? } else { Console.WriteLine(">>> ERROR: New account for customer {0} was not created.", customerName); Console.WriteLine(""); } } else { //set continueInput to false to exit loop continueInput = false; } Console.WriteLine(""); } while (continueInput); //Function to get random number int GetRandomNumber(int min, int max) { //ensures random number generation //readonly Random getrandom = new Random(); //why can I not do readonly ??? //Random getrandom = new Random(); lock (getrandom) // synchronize { return(getrandom.Next(min, max)); } } //display each account details if (listAccounts.Count() > 0) { int listLength = listAccounts.Count(); foreach (SavingsAccount account in listAccounts) { //create loop for 6 months for (int i = 1; i < 7; i++) { //Console.WriteLine("Month {0} starting balance is {1}.", i, account.Balance); //deduct monthly fee account.DeductMonthlyFee(account.Balance); //Console.WriteLine("After deducting monthly fee the remaining balance is {0}", account.Balance); //add monthly interest account.AddMonthlyInterest(account.Balance); //Console.WriteLine("After adding monthly interest the balance is {0}", account.Balance); //add monthly deposit account.AddMonthlyDeposit(account.Balance); //Console.WriteLine("After adding the monthly deposit the balance is now {0}", account.Balance); //Console.WriteLine(""); } //Console.WriteLine("Account Number: " + account.AccountNumber); //Console.WriteLine("Account Owner: " + account.Owner); //Console.WriteLine("Monthly Deposit: " + account.MonthlyDeposit); //Console.WriteLine("Current Balance: " + account.Balance); Console.WriteLine("After 6 months, {0} (Account# {1}) has a balance of {2}", account.Owner, account.AccountNumber, account.Balance.ToString("C", CultureInfo.CurrentCulture)); } } }