-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
113 lines (97 loc) · 3.18 KB
/
Program.cs
File metadata and controls
113 lines (97 loc) · 3.18 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
namespace classProgramm
{
class Program
{
static void Main(string[] args)
{
bool doContinue;
do
{
doSmthg();
Console.WriteLine("Do you want to do another job (y/n)");
char response = char.Parse(Console.ReadLine());
if (response == 'y')
{
doContinue = true;
}
else
{
doContinue = false;
Console.WriteLine("Goodbye");
}
} while (doContinue);
}
static void doSmthg()
{
double amound;
Account customer = new Account("Dimitris", 400, 1);
Console.WriteLine("press 'w' for withdraw or 'd' for deposite");
char action;
action = char.Parse(Console.ReadLine());
if (action == 'w')
{
Console.WriteLine("type the amount");
amound = double.Parse(Console.ReadLine());
bool success = customer.withdraw(amound);
if (success) Console.WriteLine("Withdrawal successfull :)");
else Console.WriteLine("Withdrawal unsuccessfull :(");
}
else if (action == 'd')
{
Console.WriteLine("Type the amount");
amound = double.Parse(Console.ReadLine());
bool success = customer.deposit(amound);
if (success) Console.WriteLine("Deposite successfull :)");
else Console.WriteLine("Deposite unsuccessfull :(");
}
else
{
Console.WriteLine("Wrong answer");
}
Console.WriteLine(customer.ToString());
}
}//End of Class Program
class Account
{
//fields
const double _depositeLimit = 5000;
string _owner;
double _balance;
int _numberOfTransaction;
//method for withdraw
public bool withdraw(double amound)
{
_numberOfTransaction++;
if (_balance < amound) return false;
_balance -= amound;
return true;
}
//method for deposit
public bool deposit(double amound)
{
_numberOfTransaction++;
if (amound > _depositeLimit) return false;
_balance += amound;
return true;
}
//empty constructor
public Account()
{
}
//main constructor
public Account(string owner, double balance, int numberOfTransaction)
{
_owner = owner;
_balance = balance;
_numberOfTransaction = numberOfTransaction;
}
//ToString
public override string ToString()
{
return "Owner: " + _owner +
"\nBalance: " + _balance +
"\nNumber of Transaction: " + _numberOfTransaction;
}
}//End of Class Account
}