void Run() { Customer cust1 = new Customer(1, "Max Tech Training"); cust1.Username = "******"; cust1.Password = "******"; cust1.Display(); Account acct1 = new Account("My First Account"); acct1.Id = 100; acct1.Deposit(100.0); acct1.Customer = cust1; acct1.Display(); acct1.Withdraw(25.0); acct1.Display(); acct1.Withdraw(1000.0); acct1.Display(); acct1.Deposit(-300.0); acct1.Display(); acct1.Withdraw(-500.0); acct1.Display(); // transfer 25 from one to another Account acct2 = new Account(); acct2.Id = 200; acct2.Description = "My second account"; acct2.Customer = cust1; acct2.Display(); acct1.Display(); acct2.Display(); acct1.Transfer(25.0, acct2); acct1.Display(); acct2.Display(); // savings class Savings sav1 = new Savings("My first savings account"); sav1.Id = 300; sav1.Customer = cust1; sav1.Deposit(500.00); sav1.Withdraw(200.00); sav1.Display(); sav1.intRate = .12; sav1.PayInterest(); sav1.Display(); sav1.IsLocked = true; try { sav1.Deposit(10.00); } catch (ApplicationException ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } double bal = acct1.Balance; // produce monthly statement cust1.MonthlyStatement(); }
void Run() { //The first Account made during this exercise, which is given the Name of "My Checking" Account checking = new Account("My Checking"); //The second Account made, which is an Account, but needs to be called Savings, because it //will use items from the Savings class, in addition to items from the Account class. As such, //during the creation of "savings," two constructors are called, the one in Account that takes //a string to give an Account a Name, and the one in Savings, that takes the Name, and the IntRate //(the interest rate). //When "savings" is created, we gave it the Name "My Savings," and the IntRate of "0.10" Savings savings = new Savings("My Savings", 0.10); //Time to test the code, let's add some money to the two accounts, and take some away from checking. checking.Deposit(100.00); checking.Withdraw(20.00); savings.Deposit(350); //Show the Number for the checking account, the Name, and its balance. Console.WriteLine($"Account # {checking.GetNumber()}, Name: {checking.GetName()} has a balance of {checking.CheckBalance()}."); Console.WriteLine($"Account # {savings.GetNumber()}, Name: {savings.GetName()} has a balance of {savings.CheckBalance()}."); //Let's transfer some money from savings to checking. savings.Transfer(340, checking); //Time to add some interest to savings. savings.PayMonthlyInterest(); //Creates a generic List, where each item is an "Account" List <Account> myAccounts = new List <Account>(); myAccounts.Add(checking); myAccounts.Add(savings); //Goes through each item on the List, each being an Account, and calls the ToPrint method. foreach (var account in myAccounts) { Console.WriteLine(account.ToPrint()); } }
static void Main(string[] args) // operating enviroment looks for this method to start running the program { Account acct1 = new Account(); // using the Account type unboxing the Account type--when using class as type use this format acct1.Id = 1; acct1.Description = "My first checking account!!"; acct1.Balance = 0.0; acct1.Owner = new Customer(100, "Greg Doud"); Console.WriteLine(acct1.ToPrint()); acct1.Deposit(5.00); Console.WriteLine(acct1.ToPrint()); acct1.Deposit(-5); Console.WriteLine(acct1.ToPrint()); acct1.Withdraw(5000.00); Console.WriteLine(acct1.ToPrint()); Savings sav2 = new Savings(); sav2.Id = 2; sav2.Description = " My first savings acct"; sav2.Balance = 0.0; sav2.Owner = new Customer(101, "Lisa S"); sav2.IntRate = .12; sav2.Deposit(1000.00); Console.WriteLine(sav2.ToPrint()); Checking ck1 = new Checking(); ck1.Id = 77; ck1.Description = "Another Checking"; ck1.Balance = 1200.00; ck1.Owner = new Customer(102, "Marty B"); ck1.Deposit(2000); Console.WriteLine(ck1.ToPrint()); Checking ck3 = new Checking(); ck3.Id = 3; ck3.Description = "Another Checking"; ck3.Balance = 1200.00; ck3.Owner = new Customer(102, "Nate B"); ck3.Deposit(2000); Console.WriteLine(ck1.ToPrint()); Checking ck2 = new Checking(); ck2.Id = 400; ck2.Description = "Another Checking"; ck2.Balance = 1200.00; ck2.Owner = new Customer(103, "Nate B"); ck2.Deposit(2000); Console.WriteLine(ck2.ToPrint()); Savings sav = new Savings(); sav.Id = 2; sav.Description = " My first savings acct"; sav.Balance = 0.0; sav.Owner = new Customer(108, "Nate B"); sav.IntRate = .12; sav.Deposit(1000.00); Account[] accounts = { sav, ck2, ck3 }; double GrandTotal = 0; foreach (Account account in accounts) { double AcctBalance = account.GetBalance(); GrandTotal = GrandTotal + account.Balance; Console.WriteLine(account.ToPrint()); } Console.WriteLine("Grand total is " + GrandTotal.ToString()); Investment inv = new Investment(); inv.Deposit(1000.00); Console.WriteLine(); Console.ReadLine(); }