forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
124 lines (102 loc) · 4.26 KB
/
Account.java
File metadata and controls
124 lines (102 loc) · 4.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.text.DecimalFormat; // Import for formatting numbers into currency format
import java.util.Scanner; // Import for taking user input from the console
public class Account {
private int customerNumber; // Stores customer number
private int pinNumber; // Stores customer's PIN
private double checkingBalance = 0; // Stores checking account balance
private double savingBalance = 0; // Stores saving account balance
Scanner input = new Scanner(System.in); // Scanner object for user input
DecimalFormat moneyFormat = new DecimalFormat("'$'###,##0.00"); // Format to display currency values
// Sets the customer number
public void setCustomerNumber(int customerNumber){
this.customerNumber = customerNumber;
}
// Returns the customer number
public int getCustomerNumber(){
return customerNumber;
}
// Sets the PIN number
public void setPinNumber(int pinNumber){
this.pinNumber = pinNumber;
}
// Returns the PIN number
public int getPinNumber(){
return pinNumber;
}
// Returns the checking account balance
public double getCheckingBalance() {
return checkingBalance;
}
// Returns the saving account balance
public double getSavingBalance(){
return savingBalance;
}
// Deducts the amount from checking account
public void calcCheckingWithdraw(double amount){
checkingBalance = (checkingBalance - amount);
}
// Deducts the amount from saving account
public void calcSavingWithdraw(double amount){
savingBalance = (savingBalance - amount);
}
// Adds the amount to checking account
public void calcCheckingDeposit(double amount){
checkingBalance = (checkingBalance + amount);
}
// Adds the amount to saving account
public void calcSavingDeposit(double amount){
savingBalance = (savingBalance + amount);
}
// Prompts user to withdraw money from checking account
public void getCheckingWithdrawInput() {
System.out.println("Checking Account balance: " + moneyFormat.format(checkingBalance));
System.out.print("Amount you want to withdraw from Checking Account: ");
double amount = input.nextDouble();
if(checkingBalance - amount >= 0){
calcCheckingWithdraw(amount);
System.out.println("New Checking Account Balance: " + moneyFormat.format(checkingBalance));
}
else{
System.out.println("Not Enough Money to Withdraw");
}
}
// Prompts user to withdraw money from saving account
public void getSavingWithdrawInput() {
System.out.println("Saving Account balance: " + moneyFormat.format(savingBalance));
System.out.print("Amount you want to withdraw from Saving Account: ");
double amount = input.nextDouble();
if(savingBalance - amount >= 0){
calcSavingWithdraw(amount);
System.out.println("New Saving Account Balance: " + moneyFormat.format(savingBalance));
}
else{
System.out.println("Not Enough Money to Withdraw");
}
}
// Prompts user to deposit money into checking account
public void getCheckingDepositInput(){
System.out.println("Checking Account Balance: " + moneyFormat.format(checkingBalance));
System.out.print("Amount you want to deposit to Checking Account: ");
double amount = input.nextDouble();
if(checkingBalance + amount >= 0){
calcCheckingDeposit(amount);
System.out.println("New Checking Account Balance: " + moneyFormat.format(checkingBalance));
}
else{
System.out.println("No Money to Deposit");
}
}
// Prompts user to deposit money into saving account
public void getSavingDepositInput(){
System.out.println("Saving Account Balance: " + moneyFormat.format(savingBalance));
System.out.print("Amount you want to deposit to Saving Account: ");
double amount = input.nextDouble();
if(checkingBalance + amount >= 0){
calcSavingDeposit(amount);
System.out.println("New Saving Account Balance: " + moneyFormat.format(savingBalance));
}
else{
System.out.println("No Money to Deposit");
}
}
}