hi i got a bank account project and i dont know how to figure out this problem
i need to be able to transfert money from checking account to saving account
if someone can help me with an exemple ,because i am a bit lost
thanks by advance

Recommended Answers

All 4 Replies

Study Following, You may get some ideas:


-Firstly, add a base interface named IBankAccount

using System;
using System.Collections.Generic;
using System.Text;

namespace BankAcc
{
        public interface IBankAccount
        {
            void PayIn(decimal amount);
            bool Withdraw(decimal amount);
            decimal Balance
            {
                get;
            }
        }
}

- Add another interface: Which is derived interface named ITransferAccount

using System;
using System.Collections.Generic;
using System.Text;

namespace BankAcc
{
    interface ITransferAccount:IBankAccount 
    {
        bool TransferTo(IBankAccount destination, decimal amount);
    }
}

-Add a class Named SaverAccount and write the following codes:

using System;
using System.Collections.Generic;
using System.Text;

namespace BankAcc.LaxmiBank
{
   public class SaverAccount:IBankAccount 
    {
       private decimal balance;
       public void PayIn(decimal amount)
       {
           balance += amount;
       }
       public bool Withdraw(decimal amount)
       {
           if (balance >= amount)
           {
               balance -= amount;
               return true;
           }
           Console.WriteLine("Withraw Attempt Failed");
           return false;
       }

       public decimal Balance
       {
           get { return balance;}
       }

       public override string ToString()
       {
           return string.Format("Laxmi Bank Saver: Balance={0,6:c}",balance);
       }
    }
}

- Now add a class named CurrentAccount and write the following codes

using System;
using System.Collections.Generic;
using System.Text;
namespace BankAcc.InvestmentBank
{
    class CurrentAccount:ITransferAccount 
    {
        private decimal balance;
        public void PayIn(decimal amount)
        {
            balance += amount;
        }

        public bool Withdraw(decimal amount)
        {
            if (balance >= amount)
            {
                balance -= amount;
                return true;
            }
            Console.WriteLine("Withdraw Attempt Failed");
            return false;
        }

        public decimal Balance
        {
            get { return balance; }
        }

        public bool TransferTo(IBankAccount destination, decimal amount)
        {
            bool result;
            if ((result = Withdraw(amount)) == true)
                destination.PayIn(amount);
            return result;
        }

        public override string ToString()
        {
            return string.Format("Investment Bank Current Account:Balance={0,6:c}", balance);
        }
    }
}

-To Test This Derived Interface write the following codes in main module:

using System;
using System.Collections.Generic;
using System.Text;
using BankAcc;
using BankAcc.LaxmiBank;
using BankAcc.InvestmentBank;

namespace BankAcc
{
    class Program
    {
        static void Main()
        {
            IBankAccount laxmiAccount = new SaverAccount();

            ITransferAccount investmentAccount = new CurrentAccount();
            laxmiAccount.PayIn(200);
            investmentAccount.PayIn(500);
            investmentAccount.TransferTo(laxmiAccount, 100);
            Console.WriteLine(laxmiAccount.ToString());
            Console.WriteLine(investmentAccount.ToString());

            Console.ReadLine();
        }
    }
}

Is this project involving databases or do you simply need two Acccount instances created that communicate?
If the later you need to create your Account class with methods (getter and setters) that alter the current amount (which will be a class variable).
Create the two classes, initialise each with a certain amount and then call your withdraw and deposit methods.

public class Account
        {
            private float balance;
            public void Deposit(float amount)
            {
                balance += amount;
            }

            public void Withdraw(float amount)
            {
                balance -= amount;
            }

            public void TransferFunds(Account destination, float amount)
            {
                this.Withdraw(amount);
                destination.Deposit(amount);
            }

            public float Balance
            {
                get { return balance; }
            }
        }

And then access like so

Account target = new Account();
target.Deposit(300.00F);
public void Withdraw()
        {            
            float amount = 200.00F; 
            target.Withdraw(amount);
        }

You were in luck, I had an old test case example lying around:)

wow thank you very much

hi sir pls provide me any bank system with all features...............

commented: Please address your question in a new thread. Also, please format your question in a manner which displays your effort done so far. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.