You need to identity the classes involed in this system and their relationship
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");
}
}
}
}
Comments
Leave a comment