Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace FileDetails
- {
- enum AccountType
- {
- Checking,
- Deposit
- }
- class BankAccount
- {
- private long accNo;
- private decimal accBal;
- private AccountType accType;
- public void Populate(decimal balance)
- {
- accNo = NextNumber();
- accBal = balance;
- accType = AccountType.Checking;
- }
- public long Number()
- { return accNo; }
- public decimal Balance()
- { return accBal; }
- public string Type()
- { return accType.ToString(); }
- private static long nextAccNo = 123;
- private static long NextNumber()
- { return nextAccNo++; }
- public decimal Deposit(decimal amount)
- {
- accBal += amount;
- return accBal;
- }
- public bool Withdraw(decimal amount)
- {
- bool sufficientFunds = accBal >= amount;
- if (sufficientFunds)
- { accBal -= amount; }
- return sufficientFunds;
- }
- }
- class CreateAccount
- {
- static void Main()
- {
- BankAccount berts = NewBankAccount();
- Write(berts);
- TestDeposit(berts);
- Write(berts);
- TestWithdraw(berts);
- Write(berts);
- BankAccount freds = NewBankAccount();
- Write(freds);
- TestDeposit(freds);
- Write(freds);
- TestWithdraw(freds);
- Write(freds);
- }
- static BankAccount NewBankAccount()
- {
- BankAccount created = new BankAccount();
- /* Console.Write("Enter the account number : ");
- long number = long.Parse(Console.ReadLine()); */
- // long number = BankAccount.NextNumber();
- Console.Write("Enter the account balance! : ");
- decimal balance = decimal.Parse(Console.ReadLine());
- /* created.accNo = number;
- created.accBal = balance;
- created.accType = AccountType.Checking; */
- created.Populate(balance);
- return created;
- }
- static void Write(BankAccount toWrite)
- {
- Console.WriteLine("Account number is {0}", toWrite.Number());
- Console.WriteLine("Account balance is {0}", toWrite.Balance());
- Console.WriteLine("Account type is {0}", toWrite.Type());
- }
- public static void TestDeposit(BankAccount acc)
- {
- Console.Write("Enter amount to deposit: ");
- decimal amount = decimal.Parse(Console.ReadLine());
- acc.Deposit(amount);
- }
- public static void TestWithdraw(BankAccount acc)
- {
- Console.Write("Enter amount to withdraw: ");
- decimal amount = decimal.Parse(Console.ReadLine());
- if (!acc.Withdraw(amount))
- { Console.WriteLine("Insufficient funds."); }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment