-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount
More file actions
188 lines (150 loc) · 4.5 KB
/
Account
File metadata and controls
188 lines (150 loc) · 4.5 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//Creation of a program of a bank
import java.util.*;
//Creating an Account class with properties
class Account{
String customerName="";
String customerAccountType="";
static int accountNumber=0;
int customerAccountNumber;
float balance;
//Parameterised constructor of Account class
Account(String name,String acctype){
customerName=name;
customerAccountType=acctype;
accountNumber++;
}
//Function for displaying balance
void DisplayBalance()
{
System.out.println("Balance: "+balance);
}
//Function for Depositing amount
void Deposit(float x)
{
balance=balance+x;
}
//Function for showing details of any customer
void showDetails()
{
System.out.println(customerName+","+customerAccountType+","+customerAccountNumber);
}
}
//Creating child class SavingAccount of parent class Account
class SavingAccount extends Account{
//Parameterised constructor of SavingAccount class
SavingAccount(String name,String acctype)
{
super(name,acctype);
customerAccountNumber=accountNumber;
}
//Function of withdrawal of money
void Withdrawal(float x)
{
if(balance>x)
balance=balance-x;
else
System.out.println("There is insufficent balance in your account");
}
}
//Creating child class CurrentAccount of parent class Account
class CurrentAccount extends Account{
float minimum_balance=1500.00f;
String penalty="false";
//Parameterised constructor of CurrentAccount class
CurrentAccount(String name,String acctype)
{
super(name,acctype);
customerAccountNumber=accountNumber;
}
//Function of Deposition of money
void Deposit(float x)
{
balance=balance+x;
if(balance>minimum_balance)
penalty="false";
}
//Function for checking passbook
void checkBook(float x){
if(balance>x){
balance=balance-x;
if(balance<minimum_balance&&!penalty.equals("paid"))
penalty="true";
}
else if(balance<x)
System.out.println("Insufficent balance in your account");
if(penalty.equals("true")){
balance=balance-200;
penalty="paid";
}
}
}
public class MyAccount{
public static void main(String args[]){
Scanner scan=new Scanner(System.in);
String y="";
float myamount;
Account myaccount=null;
do{
System.out.println("Choose any one :");
System.out.println("1 -Do you already have an account?");
System.out.println("2 -Create a new account for me!!");
int option=scan.nextInt();
if(option==2){
System.out.println("\n Which account you wish to create? ");
System.out.println("1 -Saving account");
System.out.println("2 -current account");
int num=scan.nextInt();
System.out.println("\nEnter your name");
String name=scan.nextLine();
switch(num){
case 1:
myaccount=new SavingAccount(name,"saving");
break;
case 2:
myaccount=new CurrentAccount(name,"current");
}
}
else if(option==1){
System.out.println("\n\n1 -Check your Balance");
System.out.println("2 -Deposit your Cash");
System.out.println("3 -Show Details of Account");
System.out.println(myaccount.customerAccountType.equals("saving")?"4 -Cash withdrawal":"4 -checkBook");
int num1=scan.nextInt();
switch(num1){
case 1:
myaccount.DisplayBalance();
break;
case 2:{
System.out.println("\nEnter Amount accordingly: ");
myamount=scan.nextFloat();
myaccount.Deposit(myamount);
}break;
case 3:
myaccount.showDetails();
break;
case 4:{
if(myaccount.customerAccountType.equals("saving"))
{
SavingAccount mySavingAccount=(SavingAccount)myaccount;
System.out.println("\nEnter Amount accordingly: ");
myamount=scan.nextFloat();
mySavingAccount.Withdrawal(myamount);
}
else{
CurrentAccount myCurrentAccount=(CurrentAccount)myaccount;
System.out.println("\n1 -Enter an amount to withdrawal through checkbook");
myamount=scan.nextFloat();
myCurrentAccount.checkBook(myamount);
}
}break;
default:
System.out.println("Incorrect option");
}
}
scan.nextLine();
System.out.println("Do you want to continue?");
System.out.println("Yes or No");
y=scan.nextLine();
}while(y.equalsIgnoreCase("yes"));
}
}