Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace BankingInterface
- {
- public partial class BankingInterface : Form
- {
- public BankingInterface()
- {
- InitializeComponent();
- }
- private void CreateAccountButton_Click(object sender, EventArgs e)
- {
- string fullName = " ";
- int accountNumber = 0;
- double initialBalance = 0.00;
- Boolean validName = false;
- Boolean validAccount = false;
- Boolean validBalance = false;
- if (string.IsNullOrWhiteSpace(AccountNameInput.Text))
- {
- MessageBox.Show("Please enter your full name.", "Error",
- MessageBoxButtons.OKCancel);
- }
- else if(Regex.IsMatch(AccountNameInput.Text, @"^[a-zA-Z ]+$"))
- {
- if(AccountNameInput.Text.Contains(" "))
- {
- fullName = AccountNameInput.Text;
- validName = true;
- }
- else
- {
- MessageBox.Show("Full name must contain a space.", "Error",
- MessageBoxButtons.OKCancel);
- }
- }
- else
- {
- MessageBox.Show("Name must not contain numbers or special characters.", "Error",
- MessageBoxButtons.OKCancel);
- }
- if (string.IsNullOrWhiteSpace(AccountNumberInput.Text))
- {
- MessageBox.Show("Please enter your account number", "Error",
- MessageBoxButtons.OKCancel);
- }
- else if(Regex.IsMatch(AccountNumberInput.Text, @"^[0-9]+$"))
- {
- accountNumber = Convert.ToInt32(AccountNumberInput.Text);
- validAccount = true;
- }
- else
- {
- MessageBox.Show("Must contain only numbers.", "Error",
- MessageBoxButtons.OKCancel);
- }
- if (string.IsNullOrWhiteSpace(InitialBalanceInput.Text))
- {
- MessageBox.Show("Please enter your initial balance", "Error",
- MessageBoxButtons.OKCancel);
- }
- else if (Regex.IsMatch(AccountNumberInput.Text, @"^[0-9.]+$"))
- {
- initialBalance = Math.Round(Convert.ToDouble(InitialBalanceInput.Text),2);
- validBalance = true;
- }
- else
- {
- MessageBox.Show("Initial balance must contain only numbers and a decimal point.", "Error",
- MessageBoxButtons.OKCancel);
- }
- if(validName == true && validAccount == true && validBalance == true)
- {
- AccountBalanceDisplay.Text = "$" + Convert.ToString(initialBalance);
- Customer cust1 = new Customer(fullName, accountNumber, initialBalance);
- }
- }
- private void ApplyButton_Click(object sender, EventArgs e)
- {
- double userInput = Convert.ToDouble(AmountInput.Text);
- if (DepositRButton.Checked)
- {
- cust1.Deposit(userInput);
- }
- }
- public class Customer
- {
- private string fullName;
- private int accountNumber;
- private double initialBalance;
- private double userInput;
- private double currentBalance;
- public Customer()
- {
- }
- public Customer(string fN, int aN, double iB)
- {
- fullName = fN;
- accountNumber = aN;
- initialBalance = iB;
- }
- public double Deposit(double uI)
- {
- userInput = uI;
- currentBalance = Math.Round((currentBalance + userInput), 2);
- return currentBalance;
- }
- public double Withdrawal(double uI)
- {
- userInput = uI;
- currentBalance = Math.Round((currentBalance - userInput), 2);
- return currentBalance;
- }
- public override string ToString()
- {
- return "$" + currentBalance;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement