-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAccount.java
84 lines (80 loc) · 1.84 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
import java.io.*;
import java.util.*;
class Account
{
double balance;
Account()
{
balance = 0;
}
Account(double sum)
{
balance = sum;
}
double add(double sum)
{
balance += sum;
return sum;
}
double withdraw(double sum)
{
if (sum > balance) {
balance -= 5;
return -5;
}
else {
this.balance -= sum;
return balance; // Notice: always >= 0 (never < 0)
}
}
double inquire()
{
return balance;
}
double interest (double rate)
{
return rate * balance;
}
}
class bank1
{
public static void main(String args[])
{
try
{
Scanner s=new Scanner(System.in);
System.out.println("Enter account holder name:");
String s1=s.next();
System.out.println("Enter account type:");
String s2=s.next();
int b=0;
System.out.println("Enter the initial value");
b=s.nextInt();
Account A;
if (b==0){
A = new Account();
}
else{
A = new Account(b);
}
System.out.println("Enter the amount to withdraw");
b=s.nextInt();
double d = A.withdraw(b);
System.out.println("Account holder name:"+s1);
System.out.println("Account type:"+s2);
if (d == -5) {
System.out.println("Penaly RS. -5 is charged since insufficient balance");
System.out.println("Currrent balance" + A.inquire());
}
else{
System.out.println("Now balance after withdraw of"+ A.inquire() + "is" + d);
}
System.out.println("Interest for current balance" + A.inquire() + " is " +
A.interest(0.006));
}
catch(Exception e)
{
System.out.println("Due to character exception");
}
}
}