Skip to content

Commit 732ccd6

Browse files
committed
Added line spacing between outputs, moved scanner from instance variable to local variable for methods.
1 parent cbb40be commit 732ccd6

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

BankApp/src/Checking.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ public class Checking extends Account{
33
private static String accountType = "Checking";
44

55
Checking(double initialDeposit){
6-
super();
76
this.setBalance(initialDeposit);
87
this.checkInterest(0);
98
}

BankApp/src/Customer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public String toString(){
3131
}
3232

3333
public String basicInfo(){
34-
return "First Name: " + firstName +
35-
" Last Name: " + lastName +
36-
" SSN: " + ssn +
37-
" Account Number: " + account.getAccountNumber();
34+
return " Account Number: " + account.getAccountNumber() + " - Name: " + firstName + " " + lastName;
3835
}
3936

4037
Account getAccount(){

BankApp/src/Menu.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
public class Menu {
1010

1111
//Instance Variables
12-
Scanner keyboard = new Scanner(System.in);
1312
Bank bank = new Bank();
1413
boolean exit;
1514

@@ -22,7 +21,7 @@ public void runMenu() {
2221
printHeader();
2322
while (!exit) {
2423
printMenu();
25-
int choice = getInput();
24+
int choice = getMenuChoice();
2625
performAction(choice);
2726
}
2827
}
@@ -35,15 +34,16 @@ private void printHeader() {
3534
}
3635

3736
private void printMenu() {
38-
System.out.println("Please make a selection: ");
37+
displayHeader("Please make a selection");
3938
System.out.println("1) Create a new Account");
4039
System.out.println("2) Make a deposit");
4140
System.out.println("3) Make a withdrawal");
4241
System.out.println("4) List account balance");
4342
System.out.println("0) Exit");
4443
}
4544

46-
private int getInput() {
45+
private int getMenuChoice() {
46+
Scanner keyboard = new Scanner(System.in);
4747
int choice = -1;
4848
do {
4949
System.out.print("Enter your choice: ");
@@ -89,7 +89,7 @@ private void performAction(int choice) {
8989

9090
private String askQuestion(String question, List<String> answers) {
9191
String response = "";
92-
Scanner input = new Scanner(System.in);
92+
Scanner keyboard = new Scanner(System.in);
9393
boolean choices = ((answers == null) || answers.size() == 0) ? false : true;
9494
boolean firstRun = true;
9595
do {
@@ -105,7 +105,7 @@ private String askQuestion(String question, List<String> answers) {
105105
System.out.print(answers.get(answers.size() - 1));
106106
System.out.print("): ");
107107
}
108-
response = input.nextLine();
108+
response = keyboard.nextLine();
109109
firstRun = false;
110110
if (!choices) {
111111
break;
@@ -115,6 +115,7 @@ private String askQuestion(String question, List<String> answers) {
115115
}
116116

117117
private double getDeposit(String accountType) {
118+
Scanner keyboard = new Scanner(System.in);
118119
double initialDeposit = 0;
119120
Boolean valid = false;
120121
while (!valid) {
@@ -142,6 +143,7 @@ private double getDeposit(String accountType) {
142143
}
143144

144145
private void createAnAccount() throws InvalidAccountTypeException {
146+
displayHeader("Create an Account");
145147
//Get account information
146148
String accountType = askQuestion("Please enter an account type: ", Arrays.asList("checking", "savings"));
147149
String firstName = askQuestion("Please enter your first name: ", null);
@@ -161,7 +163,8 @@ private void createAnAccount() throws InvalidAccountTypeException {
161163
bank.addCustomer(customer);
162164
}
163165

164-
private double getAmount(String question) {
166+
private double getDollarAmount(String question) {
167+
Scanner keyboard = new Scanner(System.in);
165168
System.out.print(question);
166169
double amount = 0;
167170
try {
@@ -173,37 +176,56 @@ private double getAmount(String question) {
173176
}
174177

175178
private void makeADeposit() {
179+
displayHeader("Make a Deposit");
176180
int account = selectAccount();
177181
if (account >= 0) {
178-
double amount = getAmount("How much would you like to deposit?: ");
182+
double amount = getDollarAmount("How much would you like to deposit?: ");
179183
bank.getCustomer(account).getAccount().deposit(amount);
180184
}
181185
}
182186

183187
private void makeAWithdrawal() {
188+
displayHeader("Make a Withdrawal");
184189
int account = selectAccount();
185190
if (account >= 0) {
186-
double amount = getAmount("How much would you like to withdraw?: ");
191+
double amount = getDollarAmount("How much would you like to withdraw?: ");
187192
bank.getCustomer(account).getAccount().withdraw(amount);
188193
}
189194
}
190195

191196
private void listBalances() {
197+
displayHeader("List Account Details");
192198
int account = selectAccount();
193199
if (account >= 0) {
200+
displayHeader("Account Details");
194201
System.out.println(bank.getCustomer(account).getAccount());
195202
}
196203
}
204+
205+
private void displayHeader(String message){
206+
System.out.println();
207+
int width = message.length() + 6;
208+
StringBuilder sb = new StringBuilder();
209+
sb.append("+");
210+
for(int i = 0; i < width; ++i){
211+
sb.append("-");
212+
}
213+
sb.append("+");
214+
System.out.println(sb.toString());
215+
System.out.println("| " + message + " |");
216+
System.out.println(sb.toString());
217+
}
197218

198219
private int selectAccount() {
220+
Scanner keyboard = new Scanner(System.in);
199221
ArrayList<Customer> customers = bank.getCustomers();
200222
if (customers.size() <= 0) {
201223
System.out.println("No customers at your bank.");
202224
return -1;
203225
}
204226
System.out.println("Select an account:");
205227
for (int i = 0; i < customers.size(); i++) {
206-
System.out.println((i + 1) + ") " + customers.get(i).basicInfo());
228+
System.out.println("\t" + (i + 1) + ") " + customers.get(i).basicInfo());
207229
}
208230
int account;
209231
System.out.print("Please enter your selection: ");

BankApp/src/Savings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ public class Savings extends Account{
33
private static String accountType = "Savings";
44

55
Savings(double initialDeposit){
6-
super();
76
this.setBalance(initialDeposit);
87
this.checkInterest(0);
98
}

0 commit comments

Comments
 (0)