-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankSystem.java
More file actions
96 lines (75 loc) · 2.63 KB
/
BankSystem.java
File metadata and controls
96 lines (75 loc) · 2.63 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
import java.util.Scanner;
public class BankSystem {
public static void main(String[] args) {
String nameAndSurname= "Kubra Temur";
int truePassword=125355;
int currentBalance=50000;
System.out.println("Welcome to bestBank"+ " "+ nameAndSurname + " " +"please log in");
Scanner scan = new Scanner(System.in);
if(logIn(truePassword)){
while(true){
showMenu();
System.out.println("please enter the number correspondes to the operation that you want to perform");
int choice = scan.nextInt();
switch(choice){
case 1:
currentBalance= viewBalance(currentBalance);
break;
case 2:
System.out.println("Please enter an amount:");
int amount=scan.nextInt();
currentBalance=withDraw(currentBalance, amount);
break;
case 3:
System.out.println("Please enter an amount:");
int amount2=scan.nextInt();
currentBalance=deposit(currentBalance, amount2);
break;
case 4:
System.out.println("Logging out completed successfully.");
return;
default:
System.out.println("Invalid operation number");
}
}
}
else{
System.out.println("Password is incorrect!");
}
}
public static void showMenu(){
System.out.println("---------MENU------------");
System.out.println("1.View balance");
System.out.println("2.Withdraw");
System.out.println("3.Deposit");
System.out.println("4.Exit");
}
public static boolean logIn (int truePassword){
Scanner scan = new Scanner(System.in);
System.out.println("Please enter your password:");
int password=scan.nextInt();
if(password==truePassword){
return true;
}
else
return false;
}
public static int viewBalance(int currentBalance){
System.out.println("Your current balance is:"+ currentBalance);
return currentBalance;
}
public static int withDraw(int currentBalance,int amount){
if(amount>currentBalance){
System.out.println("Insufficient funds");
return currentBalance;
}
currentBalance-=amount;
System.out.println("Operation successfull new balance is :" + currentBalance);
return currentBalance;
}
public static int deposit(int currentBalance,int amount){
currentBalance+=amount;
System.out.println("Operation successfull new balance is :" + currentBalance);
return currentBalance;
}
}