-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount .cs
More file actions
81 lines (72 loc) · 2.71 KB
/
BankAccount .cs
File metadata and controls
81 lines (72 loc) · 2.71 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
//Инкапсуляция в классе "Банковский счет":
//Напишите класс BankAccount с полями AccountNumber, Balance и Owner.
//Реализуйте методы для депозита и снятия средств, обеспечив проверку корректности операций.
//Создайте объекты класса и выполните несколько операций.
namespace ClassInheritance
{
public class BankAccount
{
private static int accountNumber = 0;
public double Balance;
public string Owner;
public static int AccountNumber
{
get
{
return accountNumber;
}
private set
{
accountNumber = value;
}
}
public BankAccount(double balance, string owner)
{
Balance = balance;
Owner = owner;
AccountNumber++;
}
public void Deposite()
{
Console.WriteLine("Введите сумму, которую хотите положить на депозит.");
double money;
while (!Double.TryParse(Console.ReadLine(), out money) || money <= 0)
Console.WriteLine("Не верный ввод.Введите сумму, которую хотите положить на депозит.");
Balance += money;
}
public void TryGetMoney()
{
Console.WriteLine("Введите сумму, которую хотите снять со счета.");
double money;
while (true)
{
if (!Double.TryParse(Console.ReadLine(), out money) || money <= 0)
{
Console.WriteLine("Не верный ввод.Введите сумму, которую хотите снять со счета.");
continue;
}
if (Balance < money)
{
Console.WriteLine($"Не достаточно средств на счету.Введите сумму меньшую {Balance}.");
continue;
}
GetMoney(money);
break;
}
}
public void GetMoney(double money)
{
Balance -= money;
}
public void Info()
{
Console.WriteLine($"Номер акаунта - {AccountNumber},\tИмя - {Owner},\tбаланс - {Balance}");
}
}
}