-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount12.java
66 lines (57 loc) · 932 Bytes
/
account12.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
import java.util.Scanner;
class account {
int accNum;
double balance;
account(int num , double bal) {
accNum = num;
balance = bal;
}
account(int num){
accNum=num;
balance=0.0;
}
int getAccountNumber() {
return accNum;
}
double getBalance() {
return balance;
}
void setBalance(double bal) {
balance = bal;
}
void credit (double amount) {
balance+=amount;
}
void debit(double am) {
if(balance >= am)
balance-=am;
else
System.out.println("amount withdrawn exceeds the current balance!");
}
public static void main(String a1[])
{
Scanner sc=new Scanner(System.in);
int b=sc.nextInt();
double d=sc.nextDouble();
account a=new account(b,d);
int t1=sc.nextInt();
switch(t1)
{
case 1:
{
double p=sc.nextDouble();
a.credit(p);
break;
}
case 2:
{
double t =sc.nextDouble();
a.debit(t);
break;
}
default:
System.out.println("Account closed");
}
System.out.println(a.getBalance());
}
}