-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientMenu.cpp
65 lines (54 loc) · 1.81 KB
/
ClientMenu.cpp
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
#include "ClientMenu.h"
//private------------------------------
vector<string> ClientMenu::allowedCommands = {"help", "deposit", "withdraw", "checkbalance", "logout"};
double ClientMenu::inputTransactionAmount(){
double amount;
std::cout << "$ Input amount:" << std::endl << ">";
std::cin >> amount;
return amount;
}
//public-------------------------------
ClientMenu::ClientMenu(BankAccount* account): account(account){}
void ClientMenu::analyzeCommand(const string& command){
if(command == allowedCommands[0]){
printHelp();
}else if(command == allowedCommands[1]){
deposit();
}else if(command == allowedCommands[2]){
withdraw();
}else if(command == allowedCommands[3]){
printBalance();
}else if(command == allowedCommands[4]){
exit();
}else{
printInvalidCommandMessage();
printHelpMessage();
}
}
void ClientMenu::printHelp(){
std::cout << "$ \"deposit\": deposit money in your bank account" << std::endl;
std::cout << "$ \"withdraw\": withdraw money from your bank account" << std::endl;
std::cout << "$ \"checkBalance\": check your bank account's balance" << std::endl;
std::cout << "$ \"logout\": logout from your account" << std::endl;
}
void ClientMenu::deposit(){
try{
double amount = inputTransactionAmount();
account->deposit(amount);
printSuccessMessage(DEPOSIT_SUCCESS);
}catch(std::logic_error e){
printFailureMessage(e.what());
}
}
void ClientMenu::withdraw(){
try{
double amount = inputTransactionAmount();
account->withdraw(amount);
printSuccessMessage(WITHDRAW_SUCCESS);
}catch(std::logic_error e){
printFailureMessage(e.what());
}
}
void ClientMenu::printBalance(){
std::cout << account->getBalance() << std::endl;
}