public static void MenuGS(GlobalSavingsAccount AGS) { string optionGS; Regex Rgx = new Regex(@"\d+\.\d+"); do { Console.WriteLine("You accessed the Global Savings page:"); Console.WriteLine(String.Format("A. Deposit\nB. Withdraw\nC. Close + Report\nD. Report Balance in USD\nR. Go Back")); optionGS = Console.ReadLine().ToUpper(); switch (optionGS) { case "A": Console.WriteLine("Enter the amount you want to deposit:"); string stringAmountD = Console.ReadLine(); if (!(Rgx.IsMatch(stringAmountD))) { throw new FormatException("The number you entered is not acceptable"); } double.TryParse(stringAmountD, out double userAmountD); AGS.MakeDeposit(userAmountD); break; case "B": Console.WriteLine("Enter the amount you want to withdraw:"); string stringAmountW = Console.ReadLine(); if (!(Rgx.IsMatch(stringAmountW))) { throw new FormatException("The number you entered is not acceptable"); } double.TryParse(stringAmountW, out double userAmountW); AGS.MakeWithdrawl(userAmountW); break; case "C": Console.WriteLine(AGS.CloseAndReport()); Console.WriteLine("The values yield a change of: {0:F2}%", AGS.GetPercentageChange()); break; case "D": Console.WriteLine(AGS.USValue(0.76).toNAMoney(true)); break; case "R": break; default: throw new InvalidOperationException("That's not what I'm looking for..."); } }while (optionGS != "R"); }
public static void GlobalSavingsMenu() { try { GlobalSavingsAccount global = new GlobalSavingsAccount(5, 1.00); StringBuilder sb = new StringBuilder(); sb.Append("Global Savings Menu\n"); sb.Append("A. Deposit\n"); sb.Append("B. Withdrawal\n"); sb.Append("C. Close + Report\n"); sb.Append("D. Report Balance in USD"); sb.Append("R. Return to Bank Menu\n"); Console.WriteLine(sb.ToString()); string sinput = Console.ReadLine().ToUpper(); switch (sinput) { case "A": bool depositerror = true; do { try { Console.WriteLine("Please enter the deposit amount:"); string deposit = Console.ReadLine(); bool validdeposit = Double.TryParse(deposit, out double depositvalue); if (validdeposit) { global.MakeDeposit(depositvalue); } else { throw new NumberValueException("\"" + deposit + "\" is not a numeric value."); } depositerror = false; } catch (NumberValueException nex) { Console.WriteLine(nex.Message); depositerror = true; } } while (depositerror); break; case "B": bool withdrawalerror = true; do { try { Console.WriteLine("Please enter the withdrawal amount:"); string withdrawal = Console.ReadLine(); bool validwithdrawal = Double.TryParse(withdrawal, out double withdrawalvalue); if (validwithdrawal) { global.MakeDeposit(withdrawalvalue); } else { throw new NumberValueException("\"" + withdrawal + "\" is not a numeric value."); } withdrawalerror = false; } catch (NumberValueException nex) { Console.WriteLine(nex.Message); withdrawalerror = true; } } while (withdrawalerror); break; case "C": global.CloseAndReport(); break; case "D": Console.WriteLine(global.GetPercentageChange()); break; case "R": MainMenu(); break; default: throw new IllegalSavingsMenuOptionException("Unkown option \"" + sinput + "\""); } } catch (IllegalSavingsMenuOptionException ex) { Console.WriteLine(ex.Message); } }