forked from Shreerang4/learning-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingSystem.java
More file actions
128 lines (110 loc) · 3.98 KB
/
BankingSystem.java
File metadata and controls
128 lines (110 loc) · 3.98 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
126
127
128
/*EXP2a Problem
write a program to simulate a simple banking system in which
the initial balance and rate of interest are read from the keyboard
and these values are initialised using the constructor member function
The program consists of the foll methods
1) to intialize the balance amount and ROI using const. mem. func
2) to make deposit
3) to withdraw an amount from the balance
4) to find compound interest based on the ROI
5) to know the balance amount
6) to display the menu options
Pseudocode:
BankAcc class:
variables:
- accno. int
- balance double
- ROI double
methods:
- menu: show all the methods
- constructor method (accno, balance, ROI)
- deposit: balance += added
- withdraw: balance -= removed
- compound interest: n years taken as parameter, then formula
- balance check: return balance
BankingSystem class:
objs:
- bankacc object created
- show all methods in a while loop
- based on input, use methods.
- end on (0)
*/
import java.util.*;
public class BankingSystem{
public static void main(String[] args){
try (Scanner sc = new Scanner(System.in)) {
System.out.println("--- Welcome to ABC Bank ---");
System.out.println("Enter your Balance: ");
double bal = sc.nextDouble();
System.out.println("Enter ROI: ");
double roi = sc.nextDouble();
System.out.println("Your Bank Account No is 111\n");
BankAcc acc = new BankAcc(111, bal, roi);
int opt = 0;
do{
acc.menu();
opt = sc.nextInt();
if(opt==1){
System.out.println("\nEnter the money to be deposited: ");
double added = sc.nextDouble();
acc.depositmoney(added);
}else if(opt==2){
System.out.println("\nEnter the money to be withdrawn: ");
double removed = sc.nextDouble();
acc.withdrawmoney(removed);
}else if(opt==3){
System.out.println("\nEnter the number of years: ");
int years = sc.nextInt();
acc.CI(years);
}else if(opt==4){
acc.balcheck();
}else if(opt==0){
break;
}else{
System.out.println("--- INPUT ERROR ---");
}
}while(opt!=0);
}
System.out.println("--- Thank you ---");
}
}
class BankAcc{
int accno;
double balance, ROI;
// Constructor method
BankAcc(int acc, double bal, double r){
this.accno = acc;
this.balance = bal;
this.ROI = r;
}
void menu(){
System.out.println("\n--- ABC BANK ---");
System.out.println("> Enter 1 to Deposit Money");
System.out.println("> Enter 2 to Withdraw Money");
System.out.println("> Enter 3 to know Compound Interest Money");
System.out.println("> Enter 4 to Check Balance");
System.out.println("> Enter 0 to Exit: ");
}
void depositmoney(double added){
this.balance += added;
System.out.println(added + " Rupees deposited to your acc."+this.accno);
}
void withdrawmoney(double remove){
if(remove>(this.balance))
System.out.println("Insufficient balance!!");
else{
this.balance -= remove;
System.out.println(remove + " Rupees withdrawn from your acc."+this.accno);
}
}
void CI(int t){
System.out.print("Compound interest on your current balance and rate of interest, after "+t+" years is: ");
double p = this.balance;
double r = this.ROI;
double amount = p*(Math.pow(1+r/100, t));
System.out.println(amount - p);
}
void balcheck(){
System.out.println("Current balance in acc."+this.accno+" is "+this.balance);
}
}