-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBank
109 lines (96 loc) · 3.76 KB
/
Bank
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
import java.util.Scanner;
public class Bank {
double balance;
double previousTransaction;
String customerName;
String customerID;
public Bank(String customerName, String customerID){
this.customerName = customerName;
this.customerID = customerID;
}
public void deposit(double amount){
if (amount != 0) {
balance += amount;
previousTransaction = amount;
}
}
public void withdraw(double amount){
if (amount > balance){
System.out.println("Not enough money in account to withdraw");
}
balance -= amount;
previousTransaction = -amount;
}
public void getpreviousTransaction(){
if (previousTransaction > 0){
System.out.println("Deposited: " + previousTransaction);
}
else if (previousTransaction < 0){
System.out.println("Withdrawn: " + Math.abs(previousTransaction));
}
else{
System.out.println("No transcation was made");
}
}
public void showMenu() {
char option = '\0';
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome " + customerName);
System.out.println("Your ID is: " + customerID);
System.out.println("\n");
System.out.println("Please select your options below");
System.out.println("A. Check 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.println("================================================================================");
System.out.println("Enter an option");
System.out.println("================================================================================");
option = scanner.next().charAt(0);
System.out.println("\n");
switch (option){
case 'A':
System.out.println("-----------------------------------");
System.out.println("Balance: " + balance);
System.out.println("-----------------------------------");
System.out.println("\n");
break;
case 'B':
System.out.println("-----------------------------------");
System.out.println("Enter an amount to deposit: ");
System.out.println("-----------------------------------");
double amount = scanner.nextDouble();
deposit(amount);
System.out.println("\n");
break;
case 'C':
System.out.println("-----------------------------------");
System.out.println("Enter an amount to withdraw: ");
System.out.println("-----------------------------------");
double amount2 = scanner.nextDouble();
withdraw(amount2);
System.out.println("\n");
break;
case 'D':
System.out.println("-----------------------------------");
getpreviousTransaction();
System.out.println("-----------------------------------");
System.out.println("\n");
break;
case 'E':
System.out.println("-----------------------------------");
break;
default:
System.out.println("Invalid option, please choose again");
break;
}
} while(option != 'E');
System.out.println("Thank you for using Phan banking! Come again!");
}
public static void main(String[] args){
Bank Datsbank = new Bank("Dat","Phanx289");
Datsbank.showMenu();
}
}