From 19ea01408873900b549b85162d5ec3a83a9ee6f1 Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Thu, 28 Nov 2024 14:54:45 +0100 Subject: [PATCH] Litt bank app --- Emne 3/BankAppMarie/BankAppMarie/Account.cs | 34 ++++++++++++-- Emne 3/BankAppMarie/BankAppMarie/Bank.cs | 49 ++++++++++++++++++++ Emne 3/BankAppMarie/BankAppMarie/Customer.cs | 41 ++++++++++++++-- Emne 3/BankAppMarie/BankAppMarie/Program.cs | 3 ++ 4 files changed, 121 insertions(+), 6 deletions(-) diff --git a/Emne 3/BankAppMarie/BankAppMarie/Account.cs b/Emne 3/BankAppMarie/BankAppMarie/Account.cs index 39c7975..de081f3 100644 --- a/Emne 3/BankAppMarie/BankAppMarie/Account.cs +++ b/Emne 3/BankAppMarie/BankAppMarie/Account.cs @@ -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; + } } } \ No newline at end of file diff --git a/Emne 3/BankAppMarie/BankAppMarie/Bank.cs b/Emne 3/BankAppMarie/BankAppMarie/Bank.cs index 7ee5cf2..9627a7b 100644 --- a/Emne 3/BankAppMarie/BankAppMarie/Bank.cs +++ b/Emne 3/BankAppMarie/BankAppMarie/Bank.cs @@ -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; + } + } + } } } \ No newline at end of file diff --git a/Emne 3/BankAppMarie/BankAppMarie/Customer.cs b/Emne 3/BankAppMarie/BankAppMarie/Customer.cs index aa3f25e..de0841a 100644 --- a/Emne 3/BankAppMarie/BankAppMarie/Customer.cs +++ b/Emne 3/BankAppMarie/BankAppMarie/Customer.cs @@ -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(); + } + } } \ No newline at end of file diff --git a/Emne 3/BankAppMarie/BankAppMarie/Program.cs b/Emne 3/BankAppMarie/BankAppMarie/Program.cs index e4c6f65..ca3716e 100644 --- a/Emne 3/BankAppMarie/BankAppMarie/Program.cs +++ b/Emne 3/BankAppMarie/BankAppMarie/Program.cs @@ -12,3 +12,6 @@ // Kunde // Regning +using BankAppMarie; + +new Bank(); \ No newline at end of file