Build a DLL for a Banking application that contains an Account base class. Decid
ID: 3867958 • Letter: B
Question
Build a DLL for a Banking application that contains an Account base class. Decide what characteristics are common for checking and saving accounts and include these characteristics in the base class. Define subclasses for Checking and Savings. In your design, do not allow the banking base account to be instantiated—only the checking and saving subclasses. Also create a Customer account such that an Account “Has-a” Customer. Create a simple test application that references your Banking DLL, to create customers and accounts and to perform simple transactions (withdraw, deposit).
Needs to be written in C#, This is what I have so far, need help with the program.cs, I'm lost on how to create a simple test application that references your Banking DLL, to create customers and accounts and to perform simple transactions (withdraw, deposit).
/* BankAccount.cs
* This is the super (base) class for other types
* of banking accounts. Checking and savings
* accounts are derived from this account.
* The class includes common attributes associated
* with banking accounts.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankingApp
{
class SavingsAccount : BankAccount
{
// Global Varibles
private decimal interestRate;
private decimal minBalance;
private decimal savingsBalance;
public SavingsAccount()
: base()
{
}
public SavingsAccount(string customerLastname, string CustomerFirstName, string id, decimal
intRate, decimal minimumBal, decimal thebalance)
: base(customerLastname, CustomerFirstName, id)
{
interestRate = intRate;
minBalance = minimumBal;
savingsBalance = thebalance;
}
internal void withdraw(int v)
{
throw new NotImplementedException();
}
internal void deposit(int v)
{
throw new NotImplementedException();
}
// Property interestRate
public Decimal InterestRate
{
get
{
return interestRate;
}
set
{
interestRate = value;
}
}
// Property minBalance
public decimal MinBalance
{
get
{
return minBalance;
}
set
{
interestRate = value;
}
}
// Property balance
public decimal Balance
{
get
{
return savingsBalance;
}
set
{
savingsBalance = value;
}
}
public override string ToString()
{
return base.ToString() + " Savings Balance " + savingsBalance.ToString("C") +
" Interest Rate: " + interestRate.ToString("P2");
}
}
}
/*CheckingAcount.cs
* This class extends BankAccount
* by including details for checking account
* customers
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankingApp
{
class CheckingAccount : BankAccount
{
private bool freeChecking;
private bool freeChecksProvided;
private bool cancelledChecksReturned;
private decimal checkingBalance;
private decimal serviceCharge;
public CheckingAccount()
: base()
{
}
public CheckingAccount(string lname, string fname, string id, bool freeCk, bool chkProv,
bool cancelCks, decimal bal, decimal serviceCh)
:base(lname, fname, id)
{
freeChecking = false;
freeChecksProvided = false;
checkingBalance = bal;
serviceCharge = serviceCh;
}
// Property freeChecking
public bool FreeChecking
{
get
{
return freeChecking;
}
set
{
freeChecking = value;
}
}
public bool FreeChecksProvided
{
get
{
return freeChecksProvided;
}
set
{
freeChecksProvided = value;
}
}
public decimal ServiceCharge
{
get
{
return serviceCharge;
}
set
{
serviceCharge = value;
}
}
public decimal CheckingBalance
{
get
{
return checkingBalance;
}
set
{
checkingBalance = value;
}
}
public bool CancelledChecksReturned
{
get
{
return CancelledChecksReturned;
}
set
{
cancelledChecksReturned = value;
}
}
public override string ToString()
{
return base.ToString() + " Checking Balance: " + checkingBalance.ToString("c") +
" Monthly Service Charge: " + serviceCharge.ToString("C");
}
}
}
/* This class extends BankAccount
* providing details regarding
* savings account objects.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankingApp
{
class SavingsAccount : BankAccount
{
// Global Varibles
private decimal interestRate;
private decimal minBalance;
private decimal savingsBalance;
public SavingsAccount()
: base()
{
}
public SavingsAccount(string customerLastname, string CustomerFirstName, string id, decimal
intRate, decimal minimumBal, decimal thebalance)
: base(customerLastname, CustomerFirstName, id)
{
interestRate = intRate;
minBalance = minimumBal;
savingsBalance = thebalance;
}
internal void withdraw(int v)
{
throw new NotImplementedException();
}
internal void deposit(int v)
{
throw new NotImplementedException();
}
// Property interestRate
public Decimal InterestRate
{
get
{
return interestRate;
}
set
{
interestRate = value;
}
}
// Property minBalance
public decimal MinBalance
{
get
{
return minBalance;
}
set
{
interestRate = value;
}
}
// Property balance
public decimal Balance
{
get
{
return savingsBalance;
}
set
{
savingsBalance = value;
}
}
public override string ToString()
{
return base.ToString() + " Savings Balance " + savingsBalance.ToString("C") +
" Interest Rate: " + interestRate.ToString("P2");
}
}
}
Explanation / Answer
Program.cs:
class Program
{
static void Main(string[] args)
{
App();
}
public static void App()
{
BankDetails bankdet = new BankDetails();
ShowMenu();
while (true)
{
Console.WriteLine("");
string userInput = Console.ReadLine();
switch (userInput)
{
case "a":
Console.WriteLine("'Citire din fisier' selected");
break;
case "b":
Console.WriteLine("'Creare cont' selected");
Console.WriteLine("");
bankdet.CreateAccount("Name 1");
bankdet.CreateAccount("Name 2");
bankdet.CreateAccount("");
bankdet.CreateAccount("Name 4");
bankdet.CreateAccount("Name 5");
break;
case "c":
Console.WriteLine("'Depunere bancara' selected");
bankdet.Deposit();
break;
case "d":
Console.WriteLine("'Retragere bancara' selected");
bankdet.Withdraw();
break;
case "e":
Console.WriteLine("'Afisare sold' selected");
bankdet.Balance();
break;
case "f":
Environment.Exit(0);
break;
default:
Console.WriteLine("Please select a valid option");
break;
}
}
}
public static void ShowMenu()
{
Console.WriteLine("a. Citire din fisier");
Console.WriteLine("b. Creare cont");
Console.WriteLine("c. Depunere bancara");
Console.WriteLine("d. Retragere bancara");
Console.WriteLine("e. Afisare sold");
Console.WriteLine("f. Iesire");
}
}
BankDetails.cs:
class BankDetails : IBankDetails
{
ReturnedVal rv = new ReturnedVal();
List<BankAccount> _accounts;
public BankDetails()
{
_accounts = new List<BankAccount>();
}
public List<BankAccount> Account
{
get { return _accounts; }
}
public void CreateAccount(string name)
{
BankAccount account = new BankAccount();
CalculateIBAN calculateIban = new CalculateIBAN();
try
{
if (!String.IsNullOrEmpty(name))
{
account.Name = name;
account.IBAN = calculateIban.IBAN();
_accounts.Add(account);
Console.WriteLine("Account created - Name: {0}, IBAN: {1}", account.Name, account.IBAN);
}
else
{
Console.WriteLine("Account name is null or empty.");
}
}
catch (NullReferenceException ne)
{
Console.WriteLine(ne.StackTrace);
}
}
public float Deposit()
{
string iban = rv.EnterIban();
BankAccount account = rv.GetAccountByName(iban, _accounts);
while (account == null)
{
Console.WriteLine("Account doesn't exist");
iban = rv.EnterIban();
account = rv.GetAccountByName(iban, _accounts);
}
float sum = rv.AmountToDeposit();
while (sum <= 0)
{
Console.WriteLine("Amount cannot be less or equal than 0.");
sum = 0;
sum = rv.AmountToDeposit();
}
account.Sum += sum;
Console.WriteLine("Added {0} to account {1}", sum, iban);
return account.Sum;
}
public float Withdraw()
{
BankDetails details = new BankDetails();
BankAccount.Comision c = Comission.Comision;
string iban = rv.EnterIban();
BankAccount account = rv.GetAccountByName(iban, _accounts);
while (account == null)
{
Console.WriteLine("Account doesn't exist");
iban = rv.EnterIban();
account = rv.GetAccountByName(iban, _accounts);
}
float sum = rv.AmountToDeposit();
while (sum <= 0)
{
Console.WriteLine("Amount cannot be less or equal than 0.");
sum = 0;
sum = rv.AmountToDeposit();
}
account.Sum -= sum;
Console.Write("Withdrawn {0} from account {1}.", sum, iban);
Console.WriteLine("Comision {0}", Math.Round(c(account.Sum), 2));
account.Sum -= c(account.Sum);
Console.WriteLine("Remaining: {0}", Math.Round(account.Sum, 2));
return account.Sum;
}
public float Balance()
{
string iban = rv.EnterIban();
BankAccount account = rv.GetAccountByName(iban, _accounts);
Console.WriteLine("IBAN: {0} has {1} left", iban, account.Sum);
return account.Sum;
}
}
IBankDetails.cs:
interface IBankDetails
{
float Balance();
void CreateAccount(string name);
float Deposit();
float Withdraw();
}
ReturnedVal.cs:
class ReturnedVal
{
internal string EnterIban()
{
Console.WriteLine("IBAN:");
string iban = Console.ReadLine();
return iban;
}
internal float AmountToDeposit()
{
Console.WriteLine("Type in the amount ");
float sum = float.Parse(Console.ReadLine());
return sum;
}
internal BankAccount GetAccountByName(string iban, List<BankAccount> _conturi)
{
BankAccount ba = _conturi.Find(c => c.IBAN == iban);
if (ba != null)
{
return ba;
}
else
{
return null;
}
}
}
CalculateIBAN.cs:
public class CalculateIBAN
{
static Random generator = new Random();
string accountNumber = generator.Next(100, 999).ToString();
public string IBAN()
{
return accountNumber;
}
}
BankAccount.cs:
public class BankAccount
{
public string Name { get; set; }
public string IBAN { get; set; }
public float Sum { get; set; }
public delegate float Comision(float comission);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.