-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
125 lines (106 loc) · 3.32 KB
/
Account.java
File metadata and controls
125 lines (106 loc) · 3.32 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
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.util.*;
abstract class Account{
long accnum;
String name;
String branch;
String IFSC;
long phnum;
Double balance;
Account(long accnum, String name, String branch, String IFSC, long phnum, Double balance){
this.accnum=accnum;
this.name = name;
this.branch = branch;
this.IFSC=IFSC;
this.phnum=phnum;
this.balance = balance;
}
abstract void deposit(Double amt);
abstract void withdraw(Double amt);
abstract void transfer(long accnum, String branch, String IFSC);
abstract void showdetails();
}
class Bank extends Account{
Bank(long accnum, String name, String branch, String IFSC, long phnum, Double balance){
super(accnum, name, branch, IFSC, phnum, balance);
}
@Override
public void deposit(Double amt){
balance += amt;
System.out.println("Deposited amount with new balance: "+balance);
}
@Override
public void withdraw(Double amt){
if(amt > balance){
System.out.println("Insufficient Balance.");
}
else{
balance -= amt;
System.out.println("Withdraw Succcesssful "+balance);
}
}
@Override
public void transfer(long accnum, String branch, String IFSC){
System.out.println("Bank Changed");
System.out.println("Account Number: "+accnum);
System.out.println("Branch: "+branch);
System.out.println("IFSC Code: "+IFSC);
}
@Override
public void showdetails(){
System.out.println("Account Number: "+accnum);
System.out.println("Name: "+name);
System.out.println("Branch: "+branch);
System.out.println("IFSC Code: "+IFSC);
System.out.println("Phone Number: "+phnum);
System.out.println("Balance: "+balance);
}
}
public class Main{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
Bank b = new Bank(12345678,"Joshua","Shollinganallur","SBI234456",73856394,7000.0);
boolean a = true;
while(a){
System.out.println("Choice: ");
System.out.println("1.Deposit \n 2.Withdraw\n3.Transfer account to another bank\n4.Show account details\n 5.Exit");
System.out.println("Enter Choice");
int choice = sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter amt to be deposited:");
Double amt = sc.nextDouble();
b.deposit(amt);
break;
case 2:
System.out.println("Enter amount to withdraw:");
amt = sc.nextDouble();
b.withdraw(amt);
break;
case 3:
System.out.print("\nEnter New Account Number: ");
long acc = sc.nextLong();
System.out.println("\nEnter new Branch Name: ");
String br = sc.next();
System.out.println("\nEnter new IFSC Code: ");
String I = sc.next();
b.accnum = acc;
b.branch = br;
b.IFSC=I;
b.transfer(acc, br, I);
break;
case 4:
b.showdetails();
break;
case 5:
System.out.println("Thank you");
a=false;
break;
default:
System.out.println("Invalid choice");
a=false;
break;
}
}
}
}