-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
102 lines (87 loc) · 2.37 KB
/
Copy pathBank.java
File metadata and controls
102 lines (87 loc) · 2.37 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
package Bank.com;
import java.util.*;
public class BankApplication {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Customer Name: ");
String name = sc.nextLine();
System.out.print("Enter Customer ID: ");
String id = sc.nextLine();
BankAccount bank = new BankAccount(name, id);
bank.showActivites();
sc.close();
}
}
class BankAccount {
int balance;
int previousTransaction;
String customerName;
String customerId;
public BankAccount(String customerName, String customerId) {
this.customerName = customerName;
this.customerId = customerId;
}
public void deposit(int amount) {
if (amount != 0) {
balance = balance + amount;
previousTransaction = amount;
}
}
public void withdraw(int amount) {
if (amount != 0) {
balance = balance - amount;
previousTransaction = -amount;
}
}
public void getpreviousTransaction() {
if (previousTransaction < 0) {
System.out.println("Withdrawn: " + Math.abs(previousTransaction));
} else if (previousTransaction > 0) {
System.out.println("Deposited: " + previousTransaction);
} else {
System.out.println("No transaction has been done.");
}
}
public void showActivites() {
char option = '\0';
Scanner sc = new Scanner(System.in);
System.out.println("Welcome: " + customerName);
System.out.println("Your ID: " + customerId);
System.out.println();
System.out.println("A. Show Balance");
System.out.println("B. Deposit");
System.out.println("C. Withdraw");
System.out.println("D. Previous Transaction");
System.out.println("E. Exit");
do {
System.out.print("\nEnter an options given above: ");
option = sc.next().charAt(0);
option = Character.toUpperCase(option);
switch (option) {
case 'A':
System.out.println("Balance is: " + balance);
break;
case 'B':
System.out.print("Enter the amount to deposit: ");
int amount = sc.nextInt();
deposit(amount);
break;
case 'C':
System.out.print("Enter the amount to withdraw: ");
int amount2 = sc.nextInt();
withdraw(amount2);
break;
case 'D':
getpreviousTransaction();
break;
case 'E':
System.out.println("Exiting... Thank you for banking with us!");
break;
default:
System.out.println("Invalid option. Please try again.");
break;
}
} while (option != 'E');
sc.close();
}
}