rendered paste bodyusing System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace BankTransactions
{
class Program
{
private Double depositValue;
private Double withdrawalValue;
private Double avgDeposit;
private Double avgWithdrawal;
private Double transactionBalance;
private int numDeposits;
private int numWithdrawals;
void Run(string[] args)
{
StreamReader objReader = File.OpenText("ATMtransactions.txt");
String strText;
Regex transactionOfInterest = new Regex("2006/9/\\d+/\\d\\d:\\d\\d,240037,([dw]),(.*)");
strText = objReader.ReadToEnd();
objReader.Close();
MatchCollection myMatches = transactionOfInterest.Matches(strText);
foreach (Match m in myMatches)
{
if (m.Groups[1].Value == "d")
{
numDeposits++;
depositValue += Convert.ToDouble(m.Groups[2].Value);
}
else if (m.Groups[1].Value == "w")
{
numWithdrawals++;
withdrawalValue += Convert.ToDouble(m.Groups[2].Value);
}
}
CalcSummaries();
DumpSummaries();
Console.ReadLine();
}
static void Main(string[] args)
{
BankTransactions bt=new BankTransactions()
bt.run(args);
}
private void CalcSummaries()
{
avgDeposit = depositValue / numDeposits;
avgWithdrawal = withdrawalValue / numWithdrawals;
transactionBalance = depositValue - withdrawalValue;
}
private void DumpSummaries()
{
Console.WriteLine("Total Deposits : " + depositValue.ToString("c"));
Console.WriteLine("Average Deposit : " + avgDeposit.ToString("c"));
Console.WriteLine("Total Withdrawals : " + withdrawalValue.ToString("c"));
Console.WriteLine("Average Withdrawal : " + avgWithdrawal.ToString("c"));
Console.WriteLine("Transaction Balance For Month : " + transactionBalance.ToString("c"));
}
}
}