Litt bank app
This commit is contained in:
parent
b4890bdccb
commit
19ea014088
|
@ -1,11 +1,39 @@
|
|||
namespace BankAppMarie
|
||||
{
|
||||
internal class Account
|
||||
public class Account
|
||||
{
|
||||
int _balance;
|
||||
private int _balance;
|
||||
string _accountName;
|
||||
bool _savingsAccount;
|
||||
string _accountNumber;
|
||||
string[] _accountTransactions;
|
||||
|
||||
public void DepositMoney(int amountToDeposit)
|
||||
{
|
||||
_balance += amountToDeposit;
|
||||
}
|
||||
|
||||
public void Withdraw(int amountToWithdraw)
|
||||
{
|
||||
if (_balance >= amountToWithdraw)
|
||||
{
|
||||
_balance -= amountToWithdraw;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Insufficient balance");
|
||||
}
|
||||
}
|
||||
|
||||
public Account(bool isSavingsAccount,string accountName)
|
||||
{
|
||||
_savingsAccount = isSavingsAccount;
|
||||
_accountName = accountName;
|
||||
}
|
||||
|
||||
public int GetAccountBalance()
|
||||
{
|
||||
return _balance;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,55 @@ namespace BankAppMarie
|
|||
{
|
||||
public class Bank
|
||||
{
|
||||
Customer _currentCustomer;
|
||||
|
||||
public Bank()
|
||||
{
|
||||
_currentCustomer = new Customer("Kåre Knutsen");
|
||||
BankMenu();
|
||||
}
|
||||
void BankMenu()
|
||||
{
|
||||
var isRunning = true;
|
||||
while (isRunning)
|
||||
{
|
||||
Console.WriteLine($"Welcome to the Bank app, {_currentCustomer.GetCustomerName()}!");
|
||||
Console.WriteLine("1. Deposit Money");
|
||||
Console.WriteLine("2. Withdraw Money");
|
||||
Console.WriteLine("3. Pay Bill");
|
||||
Console.WriteLine("4. Transfer Money to savings");
|
||||
Console.WriteLine("5. Check account balance");
|
||||
Console.WriteLine("6. Exit");
|
||||
|
||||
var userInput = Console.ReadLine();
|
||||
int userInputInt;
|
||||
|
||||
switch (userInput)
|
||||
{
|
||||
case "1":
|
||||
Console.WriteLine("Enter amount of money to deposit: ");
|
||||
userInputInt = Convert.ToInt32(Console.ReadLine());
|
||||
_currentCustomer.DepositToSavingsAccount(userInputInt);
|
||||
Console.Clear();
|
||||
break;
|
||||
case "2":
|
||||
Console.WriteLine("Enter amount of money to withdraw: ");
|
||||
userInputInt = Convert.ToInt32(Console.ReadLine());
|
||||
_currentCustomer.WithdrawMoney(userInputInt, true);
|
||||
break;
|
||||
case "3":
|
||||
break;
|
||||
case "4":
|
||||
break;
|
||||
case "5":
|
||||
var accountBalance = _currentCustomer.GetAccountBalance();
|
||||
Console.WriteLine($"{accountBalance}");
|
||||
break;
|
||||
case "6":
|
||||
isRunning = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,46 @@
|
|||
namespace BankAppMarie
|
||||
{
|
||||
public class Customer
|
||||
internal class Customer
|
||||
{
|
||||
string _CustomerName;
|
||||
string _customerName;
|
||||
string _socialSecurityNumber;
|
||||
Account _savingsAccount;
|
||||
Account _currentAccount;
|
||||
|
||||
public Customer(string customerName)
|
||||
{
|
||||
_customerName = customerName;
|
||||
_savingsAccount = new Account(true, "Savings");
|
||||
_currentAccount = new Account(false, "Brukskonto");
|
||||
}
|
||||
|
||||
|
||||
public string GetCustomerName()
|
||||
{
|
||||
return _customerName;
|
||||
}
|
||||
|
||||
public void DepositToSavingsAccount(int amount)
|
||||
{
|
||||
_savingsAccount.DepositMoney(amount);
|
||||
}
|
||||
|
||||
public void WithdrawMoney(int amount, bool fromSavingsAccount)
|
||||
{
|
||||
if (fromSavingsAccount)
|
||||
{
|
||||
_savingsAccount.Withdraw(amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentAccount.Withdraw(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetAccountBalance()
|
||||
{
|
||||
return _currentAccount.GetAccountBalance();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -12,3 +12,6 @@
|
|||
// Kunde
|
||||
// Regning
|
||||
|
||||
using BankAppMarie;
|
||||
|
||||
new Bank();
|
Loading…
Reference in a new issue