public static void Main(string[] args) { Account acc = new Account(100); ShowBalance(acc); string cmd; InputWrapper iw = new InputWrapper(); Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString("> "); while (!cmd.Equals("quit")) { try { if (cmd.Equals("deposit")) { decimal amount = iw.getDecimal("amount: "); acc.Deposit(amount); ShowBalance(acc); } else if (cmd.Equals("withdraw")) { decimal amount = iw.getDecimal("amount: "); try { acc.Withdraw(amount); } catch (BalanceException e) { Console.WriteLine("You are short {0:C}", e.Shortage); Console.WriteLine("Please make a deposit"); decimal supplemental = iw.getDecimal("amount: "); acc.Deposit(supplemental); acc.Withdraw(amount); // try again } finally { ShowBalance(acc); } } else if (cmd.Equals("show")) { ShowBalance(acc); } else { help(); } } catch (Exception e) { Console.WriteLine(e.Message); } cmd = iw.getString("> "); } }
public static void ProcessAccount(Account acc) { ShowBalance(acc); string cmd; InputWrapper iw = new InputWrapper(); Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString(acc.Prompt); while (!cmd.Equals("quit")) { try { if (cmd.Equals("deposit")) { decimal amount = iw.getDecimal("amount: "); acc.Deposit(amount); ShowBalance(acc); } else if (cmd.Equals("withdraw")) { decimal amount = iw.getDecimal("amount: "); acc.Withdraw(amount); ShowBalance(acc); } else if (cmd.Equals("owner")) { string owner = iw.getString("new owner name: "); acc.Owner = owner; show(acc); } else if (cmd.Equals("show")) { show(acc); } else { accountHelp(); } } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } cmd = iw.getString(acc.Prompt); } }
public static void Main() { Bank bank = new Bank(); InputWrapper iw = new InputWrapper(); string cmd; Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString("> "); while (!cmd.Equals("quit")) { if (cmd.Equals("open")) { AccountType type; string stype = iw.getString("account type: "); switch (stype) { case "checking": type = AccountType.Checking; break; case "savings": type = AccountType.Savings; break; default: type = AccountType.Invalid; break; } if (type == AccountType.Invalid) { Console.WriteLine("Valid account types are checking/savings"); continue; } decimal bal = iw.getDecimal("starting balance: "); string owner = iw.getString("owner: "); int id = bank.AddAccount(type, bal, owner); Console.WriteLine("Account opened, id = {0}", id); } else if (cmd.Equals("close")) { int id = iw.getInt("account id: "); bank.DeleteAccount(id); } else if (cmd.Equals("show")) { ShowArray(bank.GetAccounts()); } else if (cmd.Equals("account")) { int id = iw.getInt("account id: "); Account acc = bank.FindAccount(id); Atm.ProcessAccount(acc); } else { help(); } cmd = iw.getString("> "); } }
public static void Main() { // Initialize accounts and show starting state accounts = new ArrayList(); Console.WriteLine("accounts.Count = {0}", accounts.Count); Console.WriteLine("accounts.Capacity = {0}", accounts.Capacity); AddAccount(100, "Bob", 1); AddAccount(200, "Mary", 2); AddAccount(300, "Charlie", 3); ShowAccounts(accounts); Console.WriteLine("accounts.Count = {0}", accounts.Count); Console.WriteLine("accounts.Capacity = {0}", accounts.Capacity); // Command processing loop InputWrapper iw = new InputWrapper(); string cmd; Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString("> "); while (!cmd.Equals("quit")) { try { if (cmd.Equals("show")) { ShowAccounts(accounts); } else if (cmd.Equals("enum")) { ShowEnum(accounts); } else if (cmd.Equals("remove")) { int id = iw.getInt("id: "); RemoveAccount(id); } else if (cmd.Equals("add")) { decimal balance = iw.getDecimal("balance: "); string owner = iw.getString("owner: "); int id = iw.getInt("id: "); AddAccount(balance, owner, id); } else { help(); } } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } cmd = iw.getString("> "); } }
public static void Main(string[] args) { Account acc = new Account(100); ShowBalance(acc); string cmd; InputWrapper iw = new InputWrapper(); Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString("> "); while (!cmd.Equals("quit")) { try { if (cmd.Equals("deposit")) { decimal amount = iw.getDecimal("amount: "); acc.Deposit(amount); ShowBalance(acc); } else if (cmd.Equals("withdraw")) { decimal amount = iw.getDecimal("amount: "); acc.Withdraw(amount); ShowBalance(acc); } else if (cmd.Equals("show")) { ShowBalance(acc); } else { help(); } } catch (Exception e) { Console.WriteLine(e.Message); } cmd = iw.getString("> "); } }
public static void ProcessAccount(Account acc) { Console.WriteLine("balance = {0}", acc.Balance); string cmd; InputWrapper iw = new InputWrapper(); Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString(acc.Prompt); while (!cmd.Equals("quit")) { if (cmd.Equals("deposit")) { decimal amount = iw.getDecimal("amount: "); acc.Deposit(amount); Console.WriteLine("balance = {0}", acc.Balance); } else if (cmd.Equals("withdraw")) { decimal amount = iw.getDecimal("amount: "); acc.Withdraw(amount); Console.WriteLine("balance = {0}", acc.Balance); } else if (cmd.Equals("owner")) { string owner = iw.getString("new owner name: "); acc.Owner = owner; show(acc); } else if (cmd.Equals("show")) { show(acc); } else { accountHelp(); } cmd = iw.getString(acc.Prompt); } }
public static int Main(string[] args) { InputWrapper iw = new InputWrapper(); decimal amount = iw.getDecimal("Amount of loan: "); // amount of loan double rate = iw.getDouble("Interest rate"); // interest rate int months = iw.getInt("Number of periods"); // number of periods // Prompt for amount of loan, interest rate, and months // Calculate monthly payment using payment() method // Display this payment decimal monthlyPayment = payment(amount, rate, months); Console.WriteLine("Your monthly payment is {0}", monthlyPayment); return(0); }
public static int Main(string[] args) { InputWrapper iw = new InputWrapper(); // get an input reader (read from stdin) int i = iw.getInt("enter integer: "); Console.WriteLine("i = {0}", i); double d = iw.getDouble("enter double: "); Console.WriteLine("d = {0}", d); decimal dec = iw.getDecimal("enter decimal: "); Console.WriteLine("dec = {0}", dec); string s = iw.getString("enter string: "); Console.WriteLine("s = {0}", s); return(0); }
public static int Main(string[] args) { InputWrapper iw = new InputWrapper(); decimal amount; // amount of loan double rate; // interest rate int months; // number of periods // Prompt for amount of loan, interest rate, and months amount = iw.getDecimal("amount: "); rate = iw.getDouble("rate: "); months = iw.getInt("months: "); // Calculate monthly payment using payment() method decimal monthlyPayment = payment(amount, rate, months); // Display this payment Console.WriteLine("The monthly payment is: {0}", monthlyPayment); Console.ReadLine(); return(0); }
public static void Main() { Bank bank = new Bank(); InputWrapper iw = new InputWrapper(); string cmd; Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString("> "); while (!cmd.Equals("quit")) { if (cmd.Equals("open")) { decimal bal = iw.getDecimal("starting balance: "); string owner = iw.getString("owner: "); int id = bank.AddAccount(bal, owner); Console.WriteLine("Account opened, id = {0}", id); } else if (cmd.Equals("close")) { int id = iw.getInt("account id: "); bank.DeleteAccount(id); } else if (cmd.Equals("show")) { ShowArray(bank.GetAccounts()); } else if (cmd.Equals("account")) { int id = iw.getInt("account id: "); Account acc = bank.FindAccount(id); Atm.ProcessAccount(acc); } else { help(); } cmd = iw.getString("> "); } }
public static void Main() { // Initialize accounts and show starting state Account[] accounts = new Account[3]; accounts[0] = new CheckingAccount(100, "Bob", 0); accounts[1] = new SavingsAccount(200, "Mary", 1); accounts[2] = new CheckingAccount(300, "Charlie", 2); ShowAccounts(accounts); acc = accounts[0]; SetInterfaces(); Console.WriteLine(istat.GetStatement()); // Command processing loop InputWrapper iw = new InputWrapper(); string cmd; Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString("> "); while (!cmd.Equals("quit")) { try { if (cmd.Equals("show")) { ShowAccounts(accounts); } else if (cmd.Equals("account")) { int id = iw.getInt("account id: "); acc = accounts[id]; SetInterfaces(); Console.WriteLine(istat.GetStatement()); } else if (cmd.Equals("deposit")) { decimal amount = iw.getDecimal("amount: "); iacc.Deposit(amount); ShowBalance(istat); } else if (cmd.Equals("withdraw")) { decimal amount = iw.getDecimal("amount: "); iacc.Withdraw(amount); ShowBalance(istat); } else if (cmd.Equals("statement")) { Console.WriteLine(istat.GetStatement()); } else if (cmd.Equals("post")) { istat.Post(); Console.WriteLine(istat.GetStatement()); } else if (cmd.Equals("month")) { istat.MonthEnd(); Console.WriteLine(istat.GetStatement()); } else if (cmd.Equals("fee")) { if (ichk == null) { Console.WriteLine("IChecking is not supported"); } else { Console.WriteLine("fee = {0:C}", ichk.Fee); } } else if (cmd.Equals("interest")) { if (isav == null) { Console.WriteLine("ISavings is not supported"); } else { Console.WriteLine("interest = {0:C}", isav.Interest); } } else if (cmd.Equals("rate")) { if (isav == null) { Console.WriteLine("ISavings is not supported"); } else { Console.WriteLine("rate = {0}", isav.Rate); } } else { help(); } } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } cmd = iw.getString("> "); } }
public static void Main() { Account acc; IChecking ichk; ISavings isav; // Initialize accounts and show starting state Account[] accounts = new Account[3]; accounts[0] = new CheckingAccount(100, "Bob", 0); accounts[1] = new SavingsAccount(200, "Mary", 1); accounts[2] = new CheckingAccount(300, "Charlie", 2); ShowAccounts(accounts); acc = accounts[0]; Console.WriteLine(acc.GetStatement()); // Command processing loop InputWrapper iw = new InputWrapper(); string cmd; Console.WriteLine("Enter command, quit to exit"); cmd = iw.getString("> "); while (!cmd.Equals("quit")) { try { if (cmd.Equals("show")) { ShowAccounts(accounts); } else if (cmd.Equals("account")) { int id = iw.getInt("account id: "); acc = accounts[id]; Console.WriteLine(acc.GetStatement()); } else if (cmd.Equals("deposit")) { decimal amount = iw.getDecimal("amount: "); acc.Deposit(amount); ShowBalance(acc); } else if (cmd.Equals("withdraw")) { decimal amount = iw.getDecimal("amount: "); acc.Withdraw(amount); ShowBalance(acc); } else if (cmd.Equals("statement")) { Console.WriteLine(acc.GetStatement()); } else if (cmd.Equals("fee")) { // cast to interface and check for exception try { ichk = (IChecking)acc; Console.WriteLine("fee = {0:C}", ichk.Fee); } catch (InvalidCastException e) { Console.WriteLine("IChecking in not supported"); Console.WriteLine(e.Message); } } else if (cmd.Equals("interest")) { // use C# "is" operator if (acc is ISavings) { isav = (ISavings)acc; Console.WriteLine("interest = {0:C}", isav.Interest); } else { Console.WriteLine("ISavings in not supported"); } } else if (cmd.Equals("rate")) { // use C# "as" operator isav = acc as ISavings; if (isav != null) { //isav = (ISavings) acc; // cast not necessary Console.WriteLine("rate = {0}", isav.Rate); } else { Console.WriteLine("ISavings in not supported"); } } else { help(); } } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } cmd = iw.getString("> "); } }