-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaBank.java
More file actions
70 lines (65 loc) · 2.4 KB
/
javaBank.java
File metadata and controls
70 lines (65 loc) · 2.4 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
import java.util.Scanner;
public class javaBank {
static Scanner sc= new Scanner(System.in);
public static void main(String[]args){
int balance=0;
boolean isrunning=true;
int choice;
while(isrunning) {
System.out.println("Welcome to java Bank system:");
System.out.println("Please select a option: ");
System.out.println("1.Deposit.");
System.out.println("2.Withdraw.");
System.out.println("3.Transfer");
System.out.println("4.Check Balance:");
System.out.println("5.Exit Program");
System.out.print("Enter your choice between 1-5: ");
choice = sc.nextInt();
switch(choice){
case 1-> {
balance+=deposit(balance);
System.out.println("Total balance after deposit: "+balance);
}
case 2-> {
balance-=withdraw(balance);
System.out.println("Total balance after withdraw: "+balance);
}
case 3->showbal(balance);
case 4->{
System.out.println("Enter account number to transfer to: ");
int accNo=sc.nextInt();
System.out.println("Enter amount to transfer: ");
int amount=sc.nextInt();
if(amount>balance)
System.out.println("Insufficient balance. ");
else{
balance-=amount;
System.out.println("Succesfull transaction ");
System.out.println("total balance: "+balance);}
}
case 5-> isrunning=false;
default-> System.out.println("Invalid choice.Try again!");
}
}
sc.close();
}
static int deposit(int balance){
System.out.print("Enter the amount to deposit: ");
int amount=sc.nextInt();
return amount;
}
static int withdraw(int balance)
{
System.out.print("Enter the amount to withdraw: ");
int amount=sc.nextInt();
if(amount>balance){
System.out.println("Insufficient balance!");
return 0;}
else{
return amount;}
}
static void showbal(int balance)
{
System.out.print("Total balance : "+balance);
}
}