-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccountManager.java
104 lines (86 loc) · 2.88 KB
/
BankAccountManager.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package Javadev;
import java.sql.SQLOutput;
import java.util.Scanner;
public class BankAccountManager {
private String accountNumber;
private String accountHolder;
private double balance=0;
private boolean transaction;
public String getAccountNumber() {
return accountNumber;
}
public String getAccountHolder() {
return accountHolder;
}
public double getBalance() {
return balance;
}
public boolean isTransaction() {
return transaction;
}
public void BankAccountManager(String accountNumber,String accountHolder,double balance){
this.accountNumber=accountNumber;
this.accountHolder=accountHolder;
this.balance=balance;
}
public void deposit(double amount){
balance+=amount;
transaction=true;
System.out.println("Deposit was successful. Your new balance is: GHc"+balance);
}
public void withdraw(double amount) {
if (balance >= amount) {
balance -= amount;
transaction = true;
System.out.println("Withdrawal succesful. Your new balance is: GHc" + balance);
}else{
transaction=false;
System.out.println("Withdrawal denied");
}
}
public String checkBalance(){
return "Your current balance is: "+ balance;
}
public static String options(){
return "1.Deposit\n"+
"2.Withdraw\n"+
"3.Check Balance";
}
public static void main(String[] args){
BankAccountManager bank= new BankAccountManager();
Scanner scan=new Scanner(System.in);
int userChoice;
int userAttempts=3;
double amount=0;
String input;
System.out.println("Welcome to your banking system!\n" +
"Please choose from the options below");
while (userAttempts<=3) {
userAttempts--;
System.out.println(options());
userChoice=scan.nextInt();
if (userChoice == 1) {
System.out.println("Please enter the amount you want to deposit");
amount = scan.nextDouble();
bank.deposit(amount);
} else if (userChoice == 2) {
System.out.println("Please enter the amount you want to withdraw");
amount = scan.nextDouble();
bank.withdraw(amount);
} else if (userChoice == 3) {
System.out.println(bank.checkBalance());
} else {
System.out.println("Please enter a valid option");
continue;
}
System.out.println("Thank you!");
System.out.println("Is there anything else you'd like to do?[Y/N]");
scan.nextLine();
if (scan.nextLine().equalsIgnoreCase("Y")){
}
else{
break;
}
}
}
}