-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankAccount.cs
57 lines (51 loc) · 1.7 KB
/
BankAccount.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace csharp_oop_practice_1
{
public class BankAccount
{
public string AccountHolder { get; set; }
public string AccountNumber { get; set; }
private double _balance;
private static Random _random = new Random();
public BankAccount(string accountHolder, double initialDeposit)
{
AccountHolder = accountHolder;
_balance = initialDeposit;
AccountNumber = GenerateAccountNumber();
}
private string GenerateAccountNumber()
{
String startWith = "ACC";
return startWith + _random.Next(1000, 9999);
}
public void Deposit(double amount)
{
if (amount > 0)
{
_balance += amount;
Console.WriteLine($"Successfully deposited ${amount}. New balance: ${_balance}");
return;
}
Console.WriteLine("Invalid deposit amount");
}
public void Withdraw(double amount)
{
if (amount > 0 && amount <= _balance)
{
_balance -= amount;
Console.WriteLine($"Successfully withdrew ${amount}. New balance: ${_balance}");
return;
}
Console.WriteLine("Invalid withdraw amount. Please ensure you have sufficient funds.");
}
public void DisplayAccountInfo()
{
Console.WriteLine($"Account Holder: {AccountHolder}");
Console.WriteLine($"Account Number: {AccountNumber}");
Console.WriteLine($"Balance: ${_balance}");
}
}
}