-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.java
177 lines (162 loc) · 5.52 KB
/
Account.java
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
import java.util.Scanner;
class baseAccount
{
String customerName;
long accountNumber;
double balance;
public void initializeAccount(String name, long number, double initialBalance)
{
customerName = name;
accountNumber = number;
balance = initialBalance;
}
public void deposit(double amount)
{
if (amount > 0)
{
balance += amount;
System.out.println("Deposit successful. New balance: " + balance);
}
else
{
System.out.println("Invalid deposit amount.");
}
}
public void withdraw(double amount)
{
if (amount > 0 && amount <= balance)
{
balance -= amount;
System.out.println("Withdrawal successful. New balance: " + balance);
}
else
{
System.out.println("Invalid withdrawal amount.");
}
}
public void displayBalance()
{
System.out.println("Account Number: " + accountNumber);
System.out.println("Customer Name: " + customerName);
System.out.println("Balance: " + balance);
}
}
class savingsAccount extends baseAccount
{
double interestRate;
public void initializeSavingAccount(String name, long number, double initialBalance)
{
initializeAccount(name, number, initialBalance);
interestRate = 3.5;
}
void computeInterest()
{
double interest = balance * interestRate / 100;
balance += interest;
System.out.println("Interest earned: " + interest);
}
}
class currentAccount extends baseAccount
{
double minimumBalance;
public void initializeCurrentAccount(String name, long number, double initialBalance)
{
initializeAccount(name, number, initialBalance);
minimumBalance = 1500;
}
public void withdraw(double amount)
{
if (amount > 0)
{
if (balance - amount >= minimumBalance)
{
balance -= amount;
System.out.println("Withdrawal successful. New balance: " + balance);
}
else
{
System.out.println("Insufficient funds. Minimum balance required: " + minimumBalance);
balance -= 350;
}
}
else
{
System.out.println("Invalid withdrawal amount.");
}
}
}
public class Account
{
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter the Name of the Customer: ");
String name = sc.nextLine();
System.out.print("Enter the Customer's Account number: ");
long accnum = sc.nextLong();
System.out.print("Enter the Balance of the Customer: ");
double balance = sc.nextDouble();
System.out.print("\nEnter the type of Bank Account: Savings for a Savings Account and Current for a Current Account, additionally enter Exit to terminate.\nEnter: ");
String type = sc.next();
double credit,debit;
boolean flag = true;
boolean choice = true;
while(flag == true)
{
switch(type)
{
case("Savings"):
{
savingsAccount save = new savingsAccount();
save.initializeSavingAccount(name,accnum,balance);
while(choice == true)
{
System.out.println("Enter the amount to be Deposited: ");
credit = sc.nextDouble();
save.deposit(credit);
System.out.println("Enter the amount to be Withdrawn: ");
debit = sc.nextDouble();
save.withdraw(debit);
System.out.println("Enter 'true' if you want to deposit/Withdraw more; else enter 'false': ");
choice = sc.nextBoolean();
if(choice == false)
{
break;
}
}
save.computeInterest();
save.displayBalance();
System.exit(0);
}
case("Current"):
{
currentAccount current = new currentAccount();
current.initializeCurrentAccount(name,accnum,balance);
while(choice == true)
{
System.out.println("Enter the amount to be Deposited: ");
credit = sc.nextDouble();
current.deposit(credit);
System.out.println("Enter the amount to be Withdrawn: ");
debit = sc.nextDouble();
current.withdraw(debit);
System.out.println("Enter 'true' if you want to deposit/Withdraw more; else enter 'false': ");
choice = sc.nextBoolean();
if(choice == false)
{
break;
}
}
current.displayBalance();
System.exit(0);
}
case ("Exit"):
System.exit(0);
default:
System.out.println("Invalid Input.");
type = sc.next();
}
}
sc.close();
}
}