-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtmInterface.java
More file actions
76 lines (72 loc) · 2.26 KB
/
AtmInterface.java
File metadata and controls
76 lines (72 loc) · 2.26 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
import java.util.Scanner;
class AtmInterface{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
BankAccount ba = new BankAccount(1000);
System.out.println("WELCOME TO ATM MACHINE");
boolean run =true;
do
{
System.out.println("Bank options\n");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Check Balance");
System.out.println("4. Exit");
System.out.println("Enter your option:");
int choose = sc.nextInt();
switch(choose)
{
case 1 :
System.out.println("Enter the amount to deposit");
double depositamt= sc.nextDouble();
ba.deposit(depositamt);
System.out.println("Deposit succesfull!!!");
break;
case 2:
System.out.println("Enter the amount to withdraw");
double withdrawamt= sc.nextDouble();
ba.withdraw(withdrawamt);
System.out.println("withdrawl sucessfull!!!");
break;
case 3:
System.out.println("Your current balance is"+ " " + ba.checkBalance());
break;
case 4:
run=false;
System.out.println("Thankyou for visting aur atm machine");
break;
default:
System.out.println("Invalid input");
}
}
while(run);
}
}
class BankAccount
{
private double bal;
BankAccount(double balance){
bal=balance;
}
public void deposit(double amt)
{
if(amt>0) {
bal += amt;
}
else
{
System.out.println("Invalid deposit amt");
}
}
public void withdraw(double wamt)
{ if(wamt>0 && bal >= wamt) {
bal= bal - wamt;
} else {
System.out.println("The balanance is insufficient");
}
}
public double checkBalance()
{
return bal;
}
}