Advertisement
Guest User

Untitled

a guest
Nov 8th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace BankingInterface
  13. {
  14.  
  15. public partial class BankingInterface : Form
  16. {
  17. public BankingInterface()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void CreateAccountButton_Click(object sender, EventArgs e)
  23. {
  24. string fullName = " ";
  25. int accountNumber = 0;
  26. double initialBalance = 0.00;
  27. Boolean validName = false;
  28. Boolean validAccount = false;
  29. Boolean validBalance = false;
  30.  
  31. if (string.IsNullOrWhiteSpace(AccountNameInput.Text))
  32. {
  33. MessageBox.Show("Please enter your full name.", "Error",
  34. MessageBoxButtons.OKCancel);
  35. }
  36. else if(Regex.IsMatch(AccountNameInput.Text, @"^[a-zA-Z ]+$"))
  37. {
  38. if(AccountNameInput.Text.Contains(" "))
  39. {
  40. fullName = AccountNameInput.Text;
  41. validName = true;
  42. }
  43. else
  44. {
  45. MessageBox.Show("Full name must contain a space.", "Error",
  46. MessageBoxButtons.OKCancel);
  47. }
  48. }
  49. else
  50. {
  51. MessageBox.Show("Name must not contain numbers or special characters.", "Error",
  52. MessageBoxButtons.OKCancel);
  53. }
  54.  
  55. if (string.IsNullOrWhiteSpace(AccountNumberInput.Text))
  56. {
  57. MessageBox.Show("Please enter your account number", "Error",
  58. MessageBoxButtons.OKCancel);
  59. }
  60. else if(Regex.IsMatch(AccountNumberInput.Text, @"^[0-9]+$"))
  61. {
  62. accountNumber = Convert.ToInt32(AccountNumberInput.Text);
  63. validAccount = true;
  64. }
  65. else
  66. {
  67. MessageBox.Show("Must contain only numbers.", "Error",
  68. MessageBoxButtons.OKCancel);
  69. }
  70.  
  71. if (string.IsNullOrWhiteSpace(InitialBalanceInput.Text))
  72. {
  73. MessageBox.Show("Please enter your initial balance", "Error",
  74. MessageBoxButtons.OKCancel);
  75. }
  76. else if (Regex.IsMatch(AccountNumberInput.Text, @"^[0-9.]+$"))
  77. {
  78. initialBalance = Math.Round(Convert.ToDouble(InitialBalanceInput.Text),2);
  79. validBalance = true;
  80. }
  81. else
  82. {
  83. MessageBox.Show("Initial balance must contain only numbers and a decimal point.", "Error",
  84. MessageBoxButtons.OKCancel);
  85. }
  86.  
  87. if(validName == true && validAccount == true && validBalance == true)
  88. {
  89. AccountBalanceDisplay.Text = "$" + Convert.ToString(initialBalance);
  90. Customer cust1 = new Customer(fullName, accountNumber, initialBalance);
  91. }
  92. }
  93.  
  94. private void ApplyButton_Click(object sender, EventArgs e)
  95. {
  96. double userInput = Convert.ToDouble(AmountInput.Text);
  97.  
  98. if (DepositRButton.Checked)
  99. {
  100. cust1.Deposit(userInput);
  101. }
  102. }
  103.  
  104. public class Customer
  105. {
  106. private string fullName;
  107. private int accountNumber;
  108. private double initialBalance;
  109. private double userInput;
  110. private double currentBalance;
  111. public Customer()
  112. {
  113.  
  114. }
  115.  
  116. public Customer(string fN, int aN, double iB)
  117. {
  118. fullName = fN;
  119. accountNumber = aN;
  120. initialBalance = iB;
  121. }
  122.  
  123. public double Deposit(double uI)
  124. {
  125. userInput = uI;
  126. currentBalance = Math.Round((currentBalance + userInput), 2);
  127. return currentBalance;
  128. }
  129.  
  130. public double Withdrawal(double uI)
  131. {
  132. userInput = uI;
  133. currentBalance = Math.Round((currentBalance - userInput), 2);
  134. return currentBalance;
  135. }
  136.  
  137. public override string ToString()
  138. {
  139. return "$" + currentBalance;
  140. }
  141. }
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement