Let’s Create, .NET! Project ATM Part 5 – Write the ATM methods
1 min read

Let’s Create, .NET! Project ATM Part 5 – Write the ATM methods

Now what we need to do here is create our methods that interacts with the user to change the balance property inside our ATM class.

We already created our add method so let’s add a method to withdraw from our balance.

 public int Withdraw(int amount)
            return Balance = Balance - amount;

Wait a minute, what about if we don’t have any in our balance account? Don’t worry about that, we deal with that later.

Now create the method that simply returns the balance property.

 public int Account()
            return Balance;

Great! Let’s update our switch case with our new methods.

                    case "Account":
                        Console.WriteLine($"\nCurrent balance: {atm.Account()}");

                    case "Withdraw":
                        Console.Write("Type amount to withdraw and press enter : ");

                        int withdraw = Int32.Parse(Console.ReadLine());
                        int resultWithdraw = atm.Withdraw(withdraw);
                        Console.WriteLine($"\nCurrent balance: {result.ToString()}");

Let’s try it out!

First we check the balance with account and it’s 0.

Now add 5 to the balance.

Now let’s withdraw 3.


Now in the final post we’ll create a log for our ATM actions.

Leave a Reply