Write a program which asks the user to open a bank account either Current or Savings. Your program will display the following menu at the start: Press 1 for Current Account Press 2 for Savings Account On the selection of account type, the user will open an account by providing an initial amount. In current account the initial amount for opening an account would be 2000 and for savings it would be 5000. After choosing the account type and opening the account with initial amount, your program will display the following menu: Press a for Deposit the money Press b for withdrawing the money 82 In current account the user cannot withdraw more than 10000 rupees. In Savings account the user cannot withdraw more than 25000. When the user withdraws amount make sure that amount should not be more than the balance in account and at the end of withdrawal transaction, there should be minimum of 500 rupees for each account. PLEASE HELP ME SOLVE THIS .
Hi,
Code has bee written in the C# Console Application and below are the code details with working output screenshots:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankAccount
{
class Program
{
static void Main(string[] args)
{
ProcessInitalProcess();
}
public static void ProcessInitalProcess()
{
int iAccountType;
bool bValue;
long iInnitilAmount = 0;
try
{
Console.WriteLine("Press 1 for Current Account Press 2 for Savings Account");
bValue = int.TryParse((Console.ReadLine()), out iAccountType);
if (iAccountType == 1)
{
//Current Account
iInnitilAmount = 2000;
}
else if (iAccountType == 2)
{
//Savings Account
iInnitilAmount = 5000;
}
else
{
//Invalid Account Type
Console.WriteLine("nvalid Account Type");
ProcessInitalProcess();
}
//Call trnasaction process
ProcessTransaction(iAccountType, iInnitilAmount);
}
catch (Exception ex) { throw ex; }
}
/// <summary>
/// PRocess Tansaction
/// </summary>
/// <param name="iAccountType"></param>
/// <param name="iInnitilAmount"></param>
public static void ProcessTransaction(int iAccountType, long iInnitilAmount)
{
try
{
string strTransType = string.Empty;
Console.WriteLine("Press a for Deposit the money Press b for withdrawing the money");
strTransType = Console.ReadLine();
///This is for Current Account
if (iAccountType == 1)
{
long lAmountToWidthdra = 0;
long lAmountToDeposite = 0;
///This is for Current Account with Deposite
if (strTransType == "a")
{
Console.WriteLine("Enter Amount to Deposite");
lAmountToDeposite = Convert.ToInt64(Console.ReadLine());
iInnitilAmount += lAmountToDeposite;
}
///This is for Current Account with Withdraw
else if (strTransType == "b")
{
Console.WriteLine("Enter Amount to WithDraw");
lAmountToWidthdra = Convert.ToInt64(Console.ReadLine());
//Check withdraw value shold not > 10000
if (lAmountToWidthdra > 10000)
{
Console.WriteLine("In Current Account the user cannot withdraw more than 10000 rupees");
}
//Check withdraw value shold not > current amount and balance should be >= 500
else if ((lAmountToWidthdra > iInnitilAmount) || ((iInnitilAmount - lAmountToWidthdra) < 500))
{
Console.WriteLine("Transaction cannot processed. Minimum Balance Amount should not be less than 500 rupees");
}
else
{
//Process the Withdra and updat the current amount
iInnitilAmount -= lAmountToWidthdra;
}
}
}
///This is for Savings Account
else if (iAccountType == 2)
{
long lAmountToWidthdra = 0;
long lAmountToDeposite = 0;
///This is for Savings Account with Deposite
if (strTransType == "a")
{
Console.WriteLine("Enter Amount to Deposite");
lAmountToDeposite = Convert.ToInt64(Console.ReadLine());
iInnitilAmount += lAmountToDeposite;
}
///This is for Savings Account with withdraw
else if (strTransType == "b")
{
//Fetch withdraw value
Console.WriteLine("Enter Amount to WithDraw");
lAmountToWidthdra = Convert.ToInt64(Console.ReadLine());
//Check withdraw value shold not > 25000
if (lAmountToWidthdra > 25000)
{
Console.WriteLine("In Savings Account the user cannot withdraw more than 25000 rupees");
}
//Check withdraw value shold not > current amount and balance should be >= 500
else if ((lAmountToWidthdra > iInnitilAmount) || ((iInnitilAmount - lAmountToWidthdra) < 500))
{
Console.WriteLine("Transaction cannot processed. Minimum Balance Amount should not be less than 500 rupees");
}
else
{
//Process the Withdra and updat the current amount
iInnitilAmount -= lAmountToWidthdra;
}
}
}
//Display current balance
Console.WriteLine("Total Amount in Account is - " + iInnitilAmount);
//Ask user to process or exit
Console.WriteLine("Press 1 for Continue and Press 0 for exit");
int iContinueOrExit = Convert.ToInt32(Console.ReadLine());
if (iContinueOrExit == 1)
{
//Continue again
ProcessTransaction(iAccountType, iInnitilAmount);
}
else // exit
System.Environment.Exit(0);
}
catch (Exception ex) { throw ex; }
}
}
}
Thanks.
Get Answers For Free
Most questions answered within 1 hours.