Answer to Question #251601 in C# for Israel

Question #251601

Create a Windows application that functions like a banking account register. Separate the business logic form the presentation layer. The graphical user interface (GUI) should allow the user to input the account name, number and balance. Ensure that the full name is entered for the customer and that only numeric values are entered for the number fields when the Create Account Button is selected. Separate the business logic from the presentation layer by creating a Customer class. Include a deposit to and withdraw from methods in the customer class to keep the balance updated. After the object of the customer class is instantiated, provide Textbox objects on your GUI for the withdrawals and deposits. A second button object should be available to update the account for withdrawal and deposit transactions showing the new balance.

  


1
Expert's answer
2021-10-15T03:07:31-0400
namespace CreateAccountProject
{
    partial class frmAccount
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.btnCreateAccount = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.txtAccountName = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtNumber = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.txtBalance = new System.Windows.Forms.TextBox();
            this.btnUpdateAccount = new System.Windows.Forms.Button();
            this.rbDeposit = new System.Windows.Forms.RadioButton();
            this.rbWithdraw = new System.Windows.Forms.RadioButton();
            this.label4 = new System.Windows.Forms.Label();
            this.txtAmount = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // btnCreateAccount
            // 
            this.btnCreateAccount.Location = new System.Drawing.Point(126, 106);
            this.btnCreateAccount.Name = "btnCreateAccount";
            this.btnCreateAccount.Size = new System.Drawing.Size(100, 27);
            this.btnCreateAccount.TabIndex = 0;
            this.btnCreateAccount.Text = " Create Account";
            this.btnCreateAccount.UseVisualStyleBackColor = true;
            this.btnCreateAccount.Click += new System.EventHandler(this.btnCreateAccount_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(41, 22);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(79, 13);
            this.label1.TabIndex = 1;
            this.label1.Text = "Account name:";
            // 
            // txtAccountName
            // 
            this.txtAccountName.Location = new System.Drawing.Point(126, 19);
            this.txtAccountName.Name = "txtAccountName";
            this.txtAccountName.Size = new System.Drawing.Size(100, 20);
            this.txtAccountName.TabIndex = 2;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(41, 48);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(47, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Number:";
            // 
            // txtNumber
            // 
            this.txtNumber.Location = new System.Drawing.Point(126, 45);
            this.txtNumber.Name = "txtNumber";
            this.txtNumber.Size = new System.Drawing.Size(100, 20);
            this.txtNumber.TabIndex = 2;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(41, 74);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(49, 13);
            this.label3.TabIndex = 1;
            this.label3.Text = "Balance:";
            // 
            // txtBalance
            // 
            this.txtBalance.Location = new System.Drawing.Point(126, 71);
            this.txtBalance.Name = "txtBalance";
            this.txtBalance.Size = new System.Drawing.Size(100, 20);
            this.txtBalance.TabIndex = 2;
            // 
            // btnUpdateAccount
            // 
            this.btnUpdateAccount.Enabled = false;
            this.btnUpdateAccount.Location = new System.Drawing.Point(126, 206);
            this.btnUpdateAccount.Name = "btnUpdateAccount";
            this.btnUpdateAccount.Size = new System.Drawing.Size(100, 27);
            this.btnUpdateAccount.TabIndex = 0;
            this.btnUpdateAccount.Text = "Update Account";
            this.btnUpdateAccount.UseVisualStyleBackColor = true;
            this.btnUpdateAccount.Click += new System.EventHandler(this.btnUpdateAccount_Click);
            // 
            // rbDeposit
            // 
            this.rbDeposit.AutoSize = true;
            this.rbDeposit.Checked = true;
            this.rbDeposit.Location = new System.Drawing.Point(98, 174);
            this.rbDeposit.Name = "rbDeposit";
            this.rbDeposit.Size = new System.Drawing.Size(61, 17);
            this.rbDeposit.TabIndex = 3;
            this.rbDeposit.TabStop = true;
            this.rbDeposit.Text = "Deposit";
            this.rbDeposit.UseVisualStyleBackColor = true;
            // 
            // rbWithdraw
            // 
            this.rbWithdraw.AutoSize = true;
            this.rbWithdraw.Location = new System.Drawing.Point(156, 174);
            this.rbWithdraw.Name = "rbWithdraw";
            this.rbWithdraw.Size = new System.Drawing.Size(70, 17);
            this.rbWithdraw.TabIndex = 3;
            this.rbWithdraw.Text = "Withdraw";
            this.rbWithdraw.UseVisualStyleBackColor = true;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(97, 151);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(46, 13);
            this.label4.TabIndex = 1;
            this.label4.Text = "Amount:";
            // 
            // txtAmount
            // 
            this.txtAmount.Location = new System.Drawing.Point(155, 148);
            this.txtAmount.Name = "txtAmount";
            this.txtAmount.Size = new System.Drawing.Size(71, 20);
            this.txtAmount.TabIndex = 2;
            // 
            // frmAccount
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(257, 252);
            this.Controls.Add(this.rbWithdraw);
            this.Controls.Add(this.rbDeposit);
            this.Controls.Add(this.txtAmount);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txtBalance);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.txtNumber);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtAccountName);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.btnUpdateAccount);
            this.Controls.Add(this.btnCreateAccount);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmAccount";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Create Account";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button btnCreateAccount;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox txtAccountName;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtNumber;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox txtBalance;
        private System.Windows.Forms.Button btnUpdateAccount;
        private System.Windows.Forms.RadioButton rbDeposit;
        private System.Windows.Forms.RadioButton rbWithdraw;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox txtAmount;
    }
}








using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace CreateAccountProject
{




    public partial class frmAccount : Form
    {
        public frmAccount()
        {
            InitializeComponent();
        }
        private BankAccount newBankAccount;
        private void btnCreateAccount_Click(object sender, EventArgs e)
        {
            string accountName=txtAccountName.Text;
            double balance;
            int number;
            if (!accountName.All(char.IsLetter))
            {
                MessageBox.Show("Enter account name as string value");
                return;
            }
            if (!int.TryParse(txtNumber.Text, out number))
            {
                MessageBox.Show("Enter account number as numeric value");
                return;
            }
            if (!double.TryParse(txtBalance.Text, out balance))
            {
                MessageBox.Show("Enter account balance as numeric value");
                return;
            }
            accountName = txtAccountName.Text;
            newBankAccount = new BankAccount(accountName,number,balance);
            MessageBox.Show("Account has been created.");
            btnUpdateAccount.Enabled = true;


        }


        private void btnUpdateAccount_Click(object sender, EventArgs e)
        {


            double amount;
            if (!double.TryParse(txtAmount.Text, out amount))
            {
                MessageBox.Show("Enter amount as numeric value");
                return;
            }
            if (rbDeposit.Checked)
            {
                newBankAccount.Deposit(amount);
            }
            else {
                newBankAccount.Withdraw(amount);
            }
            txtBalance.Text = newBankAccount.Balance.ToString();
        }


      
    }
}





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace CreateAccountProject
{
    public class BankAccount
    {
        private string accountName;


        public string AccountName
        {
            get { return accountName; }
            set { accountName = value; }
        }
        private int number;


        public int Number
        {
            get { return number; }
            set { number = value; }
        }
        private double balance;


        public double Balance
        {
            get { return balance; }
            set { balance = value; }
        }


        public BankAccount(string accountName, int number, double balance)
        {
            this.accountName = accountName;
            this.number = number;
            this.balance = balance;
        }




        public void Deposit(double amount)
        {
            balance += amount;
            MessageBox.Show("The amount has been deposited to account number " + number.ToString());




        }




        public void Withdraw(double amount)
        {
            if (amount <= balance)
            {
                balance -= amount;
                MessageBox.Show("The amount has been withdrawed from account number " + number.ToString());
            }
        }




        public void DisplayCurrentBalance()
        {
            MessageBox.Show("The current balance of the account " + number.ToString() + " is: " + balance.ToString("C"));
        }




    }
}












Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS