Answer to Question #319075 in C# for mahesh

Question #319075

An ATM allows users to perform basic financial transactions:

  1. View account balance
  2. Withdraw cash
  3. Deposit cheque

You need to identity the classes involed in this system and their relationship

Identifying the Classes

  1. An ATM machine interacts with the bank for performing bank operations.
  2. The machine identifies the bank based on the card number provided
  3. Once the bank is identified it should validate the card based on pin number provided
  4. If the pin is valid, ATM application should then provide options to:
  • Deposit Amount - through cheque
  • Withdraw Amount - based on balance available
  • Check Balance
  1. It should record the card number, the bank details, the date and time of transaction, the type of transaction (deposit/withdraw/balance-enquiry) and the status of transaction (success/failure)
  2. For each failed transaction, the further processing should stop and display appropriate message
  3. At a time, ATM accepts request for single transaction.
  4. Entire process repeats, for the next transaction
1
Expert's answer
2022-03-28T11:01:15-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using BankAccountLibrary;




namespace Q212610
{




    enum TypeTransaction { VIEW_ACCOUNT_BALANCE = 1, WITHDRAW = 2, DEPOSIT = 3, EXIT = 4 }


    class Transaction
    {


        private DateTime timeTransaction;


        public DateTime TimeTransaction
        {
            get { return timeTransaction; }
            set { timeTransaction = value; }
        }
        private TypeTransaction typeTransaction;


        internal TypeTransaction TypeTransaction
        {
            get { return typeTransaction; }
            set { typeTransaction = value; }
        }
        private string status;


        public string Status
        {
            get { return status; }
            set { status = value; }
        }




        public Transaction() { }


        public Transaction(TypeTransaction typeTransaction, string status)
        {


            this.timeTransaction = DateTime.Now;
            this.typeTransaction = typeTransaction;
            this.status = status;


        }


        public override string ToString()
        {
            return "Time transaction: " + timeTransaction + Environment.NewLine +
                "Type transaction: " + typeTransaction + Environment.NewLine +
                "Status: " + status + Environment.NewLine + Environment.NewLine;
        }


    }






    public class BankAccount
    {
        private double balance;
        private string cardNumber;
        private string _PIN;


        public string PIN
        {
            get { return _PIN; }
            set { _PIN = value; }
        }


        public string CardNumber
        {
            get { return cardNumber; }
            set { cardNumber = value; }
        }
        private List<Transaction> transactions = new List<Transaction>();


        public BankAccount(double amount)
        {
            balance = amount;
            cardNumber = "123456789";
            _PIN = "1111";
        }




        public void Deposit(double amount)
        {
            if (amount > 0)
            {
                balance += amount;
                Console.WriteLine("The amount has been deposited.");
                transactions.Add(new Transaction(TypeTransaction.DEPOSIT, "success"));
            }
            else
            {
                Console.WriteLine("Wrong the amount.");
                transactions.Add(new Transaction(TypeTransaction.DEPOSIT, "failure"));
            }




        }




        public void Withdraw(double amount)
        {
            if (amount <= balance)
            {
                balance -= amount;
                Console.WriteLine("The amount has been withdrawed.");
                transactions.Add(new Transaction(TypeTransaction.WITHDRAW, "success"));
            }
            else
            {
                Console.WriteLine("The amount has NOT been withdrawed. WRONG amount.");
                transactions.Add(new Transaction(TypeTransaction.WITHDRAW, "failure"));
            }
        }




        public void DisplayCurrentBalance()
        {
            Console.WriteLine("The card number is: {0}", cardNumber);
            Console.WriteLine("The current balance of the account is: {0}", balance);
            for (int i = 0; i < transactions.Count; i++)
            {
                Console.WriteLine(transactions[i].ToString());
            }
        }
    }
    class Program
    {


        static void Main(string[] args)
        {




            TypeTransaction option = TypeTransaction.VIEW_ACCOUNT_BALANCE;
            double amount;
            BankAccount userAccount = new BankAccount(0);
            Console.Write("Enter card number: ");
            string cardNumber = Console.ReadLine();
            Console.Write("Enter PIN: ");
            string _PIN = Console.ReadLine();
            if (cardNumber.CompareTo("123456789") == 0 && _PIN.CompareTo("1111") == 0)
            {




                while (option != TypeTransaction.EXIT)
                {


                    //Main menu
                    Console.WriteLine("1. View account balance");
                    Console.WriteLine("2. Withdraw cash");
                    Console.WriteLine("3. Deposit cheque");
                    Console.WriteLine("4. Exit.");
                    Console.Write("Your choice: ");
                    option = (TypeTransaction)int.Parse(Console.ReadLine());
                    //Deposit an amount into the account
                    if (option == TypeTransaction.DEPOSIT)
                    {
                        Console.Write("Enter the amount to deposit: ");
                        double.TryParse(Console.ReadLine(), out amount);
                        userAccount.Deposit(amount);
                    }
                    else if (option == TypeTransaction.WITHDRAW)//Withdraw an amount from the account.
                    {
                        Console.Write("Enter the amount to withdraw: ");
                        double.TryParse(Console.ReadLine(), out amount);
                        userAccount.Withdraw(amount);
                    }
                    else if (option == TypeTransaction.VIEW_ACCOUNT_BALANCE)//View the current balance of the account
                    {
                        userAccount.DisplayCurrentBalance();
                    }
                    else if (option == TypeTransaction.EXIT)
                    {
                        //Exit
                    }
                    else
                    {
                        Console.WriteLine("Wrong menu item.");
                    }
                }
            }
            else
            {
                Console.WriteLine("Wrong PIN or card");
            }
        }




    }
}

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