FORONDA, JOHN DAVE D.
= LEADER BSCS 2A
TANGONAN, JUNE ASSHLEY C.
Banking System
Storing personal information and modifying the stored balance in an
account using a terminal-based program that will store those entered
information in an txt-based file. There are two txt-based files that this
Banking System will store on, the first would be where the personal
information (Personal ID, Given Name, Middle Name, Surname, and
Password) of the accounts will be stored then the second would be
where the balance of the accounts will be stored at.
Features:
o Stores accounts personal ID, Given Name, Middle Name,
Surname, Password and Balance
o It can login to an account, if the password given is right
o It can create a new account, with having 0 pesos as the default
balance
o It can view the available accounts, not showing the password
o It can deposit an entered amount of money to the balance of an
account
o It can withdraw an entered amount of money to the balance of
an account
o It can view the available balance of an account
Photo 1.0 Logging in to an already created account
Photo 1.1 Creating a new account
Photo 1.2 Viewing available accounts
Photo 2.0 Depositing entered amount of money to the currently logged in account
Photo 2.1 Withdrawing entered amount of money to the currently logged in account
Photo 2.2 Viewing balance to the currently logged in account
Photo 3.0 Txt File where personal Photo 3.1 Txt File where balance of an
Information of an account are being account is being stored at
stored at
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace FileHandling
{
class Banking
{
static void Main(string[] args)
{
string user = Environment.UserName;
string dirPath = ("C:\\Users\\"+ user + "\\Desktop\\FileHandling");
string filePathaccount = ("C:\\Users\\"+ user +
"\\Desktop\\FileHandling\\Account.txt");
string filePathbank = ("C:\\Users\\"+ user +
"\\Desktop\\FileHandling\\Bank.txt");
int choice = 0;
dirFilechecker(dirPath, filePathaccount, filePathbank);
while (choice != 4)
{
Console.WriteLine("----Welcome to UNP BANKING SYSTEM!----");
Console.WriteLine("|Main Options| [1] Login Account " +
"[2] Create Account [3] View Accounts [4] Exit System\n");
Console.Write(">> Enter the Number of your Choice: ");
string sCh = Console.ReadLine();
choice = int.Parse(sCh);
switch (choice)
{
case 1:
loginAccount(filePathaccount, filePathbank);
break;
case 2:
createAccount(filePathaccount, filePathbank);
break;
case 3:
viewAccounts(filePathaccount);
break;
case 4:
Console.WriteLine("\n----Exiting System...----\n");
break;
default:
Console.WriteLine("\n----Invalid Option Number! " +
"Please Enter Valid Option Number!----\n");
break;
}
}
}
static void dirFilechecker (string dirPath, string filePathaccount,
string filePathbank)
{
if (Directory.Exists(dirPath))
{
if (File.Exists(filePathaccount))
{
}
else
{
File.Create(filePathaccount);
}
if (File.Exists(filePathbank))
{
}
else
{
File.Create(filePathbank);
}
}
else
{
Directory.CreateDirectory(dirPath);
File.Create(filePathbank);
File.Create(filePathaccount);
}
static void loginAccount(string filePathaccount, string filePathbank)
{
string[] account = File.ReadAllLines(@filePathaccount);
if (account == null || account.Length == 0)
{
Console.WriteLine("\n----There is no Registered Account!----" +
"\n----Please Register First!----\n");
}
else
{
bool choice = true;
while (choice != false)
{
string[,] twoDimmaccount = convertTwodimm(account);
viewAccounts(filePathaccount);
Console.Write("Enter the Slot # you want to Login into: ");
string sNum = Console.ReadLine();
int slotNum = int.Parse(sNum);
int index = slotNum - 1;
if (slotNum <= 0 || slotNum > twoDimmaccount.GetLength(0))
{
Console.WriteLine("\n----Slot Does not exist... " +
"Please enter existing slot...----\n");
}
else
{
Console.Write("Enter the Password for account " +
twoDimmaccount[index, 1] + " " +
twoDimmaccount[index, 3] +" :");
string password = Console.ReadLine();
if (password != twoDimmaccount[index, 4])
{
Console.WriteLine("\n----Incorrect Password!----\n");
}
else
{
choice = false;
int options = 0;
Console.WriteLine("\n----You are now Logged in " +
"to account " +
twoDimmaccount[index, 1] + " " +
twoDimmaccount[index, 3] + "----\n");
while (options != 4)
{
Console.WriteLine("|Account Options| " +
"[1] Deposit " +
"[2] Withdraw " +
"[3] View Balance " +
"[4] Exit System\n");
Console.Write(">> Enter the Number " +
"of your Choice: ");
string sOpt = Console.ReadLine();
options = int.Parse(sOpt);
switch (options)
{
case 1:
depositBalance(filePathbank, index);
break;
case 2:
withdrawBalance(filePathbank, index);
break;
case 3:
viewBalance(filePathbank, index);
break;
case 4:
Console.WriteLine("\n----Exiting " +
"System----\n");
break;
default:
Console.WriteLine("\n----Invalid " +
"Option Number! " +
"Please Enter Valid " +
"Option Number!----\n");
break;
}
}
}
}
}
}
}
static void createAccount(string filePathaccount, string filePathbank)
{
string[] newAccount = new string[5];
string[] newBalance = { "0" };
Console.Write("Enter ID# of your Account: ");
newAccount[0] = Console.ReadLine();
Console.Write("Enter FirstName of your Account: ");
newAccount[1] = Console.ReadLine();
Console.Write("Enter MiddleName of your Account: ");
newAccount[2] = Console.ReadLine();
Console.Write("Enter LastName of your Account: ");
newAccount[3] = Console.ReadLine();
Console.Write("Enter Password of your Account: ");
newAccount[4] = Console.ReadLine();
File.AppendAllLines(filePathaccount, newAccount);
File.AppendAllLines(filePathbank, newBalance);
Console.WriteLine("\n----Account Succesfully Created!----\n");
}
static void viewAccounts(string filePathaccount)
{
string[] account = File.ReadAllLines(@filePathaccount);
try
{
if (account == null || account.Length == 0)
{
Console.WriteLine("\n----There is no " +
"Registered Account!----" +
"\n----Please Register First!----\n");
}
else
{
string[,] twoDimmaccount = convertTwodimm(account);
for (int i = 0; i < twoDimmaccount.GetLength(0); i++)
{
Console.Write("[" + (i + 1) + "] ");
for (int j = 0; j < 4; j++)
{
Console.Write(twoDimmaccount[i, j] + "\t");
}
Console.WriteLine();
}
}
}
catch
{
Console.WriteLine("\n----There is no Registered Account!----" +
"\n----Please Register First!----\n");
}
static void depositBalance (string filePathbank, int index)
{
string[] txtBalance = File.ReadAllLines(filePathbank);
int[] intBalance = getBalance(txtBalance);
Console.Write("Enter amount in Php: ");
string sAm = Console.ReadLine();
int amount = int.Parse(sAm);
intBalance[index] = intBalance[index] + amount;
string[] balance = convertTostring(intBalance);
File.WriteAllLines(filePathbank, balance);
Console.WriteLine("\n----You have successfully deposited Php" +
sAm + "----\n");
}
static void withdrawBalance (string filePathbank, int index)
{
string[] txtBalance = File.ReadAllLines(filePathbank);
int[] intBalance = getBalance(txtBalance);
Console.Write("Enter amount in Php: ");
string sAm = Console.ReadLine();
int amount = int.Parse(sAm);
if (amount > intBalance[index])
{
Console.WriteLine("\n----Not enough Balance to Withdraw!----\n");
}
else
{
intBalance[index] = intBalance[index] - amount;
string[] balance = convertTostring(intBalance);
File.WriteAllLines(filePathbank, balance);
Console.WriteLine("\n----You have successfully withdrawed Php" +
sAm + "----\n");
}
}
static void viewBalance (string filePathbank, int index)
{
string[] txtBalance = File.ReadAllLines(filePathbank);
Console.WriteLine("\n----The Balance of your Account is: Php" +
txtBalance[index] + "----\n");
}
static string[,] convertTwodimm (string[] account)
{
int index = 0;
int rows = account.Length / 5;
int columns = 5;
string[,] twoDimmaccount = new string[rows, columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
twoDimmaccount[i, j] = account[index];
index++;
}
}
return twoDimmaccount;
}
static int[] getBalance (string[] txtBalance)
{
int[] balance = Array.ConvertAll(txtBalance, int.Parse);
return balance;
}
static string[] convertTostring (int[] intBalance)
{
string[] txtBalance = Array.ConvertAll(intBalance, x=>x.ToString());
return txtBalance;
}
}
}