Please I have a c# assignment. To create a banking application that allows a teller open an account for a customer and perform transactions of deposit and withdrawal. No need for GUI. Ive used generics(I don't know if that is right). My code is below. But now I'm trying to add a .txt file so that any account created will be stored in that file because when I run the code and create an account, it goes away when I stop running. Also I'm hardcoding account numbers, I don't know how to go about that. I tried using random number generation, but when I run the code, it generates a new random number everytime. so I took it out, please help me!!!! This my code below.
The Generic Account class is below.
public class Account<T>: Person where T:class
{
private static List<Account<T>> _accounts;
private double _AccountBalance;
private string _AccountName;
private long _AccountNumber;
public Account(string Name, long accountnumber, double initialBalance)
{
AccountBalance = initialBalance;
AccountName = Name;
AccountNumber = accountnumber;
}
public double AccountBalance
{
get { return _AccountBalance; }
set { _AccountBalance = value; }
}
public string AccountName
{
get { return _AccountName; }
set { _AccountName = value; }
}
public long AccountNumber
{
get { return _AccountNumber; }
set { _AccountNumber = value; }
}
public static List<Account<T>> Accounts
{
get { return _accounts; }
set { _accounts = value; }
}
public static List<Account<T>> saveAccount(Account<T> a)
{
Accounts.Add(a);
return Accounts;
}
public virtual string getBalance(long Accountnumber)
{
return string.Format("{0:C}", AccountBalance); //currency format
}
public virtual double makeDeposit(long Accountnumber, double amount)
{
AccountBalance = AccountBalance + amount;
return AccountBalance;
}
public virtual double makeWithdrawal(long Accountnumber, double amount)
{
AccountBalance = AccountBalance - amount;
return AccountBalance;
}
public static StringBuilder AccountInfo(Account<T> a)
{
StringBuilder customerAccountInfo = new StringBuilder();
customerAccountInfo.Append("\nAccount Name: " + a.AccountName);
customerAccountInfo.Append("\nAccount Number: " + a.AccountNumber);
customerAccountInfo.Append("\nType of Account: " + typeof(T));
customerAccountInfo.Append("\nPresent account balance: " + a.getBalance(a.AccountNumber));
return customerAccountInfo;
}
}
public class Current : Account<Current>
{
public Current(string accountName, long accountNumber, double accountBalance)
: base(accountName, accountNumber, accountBalance)
{
}
public static double overdraftWithdraw(Account<Current> a, long Accountnumber, double amount)
{
a.AccountBalance = a.AccountBalance - amount;
return a.AccountBalance;
}
}
}
public class Savings: Account<Savings>
{
public Savings(string accountName, long accountNumber, double accountBalance)
: base(accountName, accountNumber, accountBalance) { }
public static double InterestOnAccount(Account<Savings> a,long accountnumber)
{
a.AccountBalance = a.AccountBalance + (BankPolicy<Savings>.interest_rate * a.AccountBalance);
return a.AccountBalance;
}
}
}
This bank policy class states the banks policy for the different account types.
public class BankPolicy<T> where T:class
{
private static double MinimumAccBalance;
private static double InterestRate;
public static double minimumBalance
{
get { return MinimumAccBalance; }
set { MinimumAccBalance = value; }
}
public static double interest_rate
{
get { return InterestRate; }
set { InterestRate = value; }
}
}
}
Please help me. :)
I'm using a list to save right now. But it goes away every time I restart the program.
private static List<Account<T>> _accounts;
public static List<Account<T>> Accounts
{
get { return _accounts; }
set { _accounts = value; }
}
public static List<Account<T>> saveAccount(Account<T> a)
{
Accounts.Add(a);
return Accounts;
}