Skip to content

Commit 30325b7

Browse files
shannoncantechshannoncantech
shannoncantech
authored and
shannoncantech
committed
Added exception to catch all and conditional within a conditional
1 parent 7179857 commit 30325b7

File tree

7 files changed

+74
-44
lines changed

7 files changed

+74
-44
lines changed

.idea/workspace.xml

+39-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/com/company/BankAccount.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*You can create an ArrayList of Person
2+
and give each person a bank account number
3+
and allow the user to set their bank balance
4+
while performing the withdrawal and deposit actions.*/
5+
16
package com.company;
27

38
import java.util.Random;
@@ -63,10 +68,10 @@ public void withdraw(int removeMoney){
6368
}
6469
}
6570

66-
//The method below creates a new account number and assigns it to the String person
67-
// This method doesn't take an integer as an argument because we don't want to assign an account number to an account number
68-
// The String person argument is perfect, so when we set Person using the person object in the main method, we'll be able to
69-
// store the person object and assign them to an account number
71+
/*The method below creates a new account number and assigns it to the String person
72+
This method doesn't take an integer as an argument because we don't want to assign an account number to an account number
73+
The String person argument is perfect, so when we set Person using the person object in the main method, we'll be able to
74+
store the person object and assign them to an account number*/
7075
public int createNewAcctNum(String person) {
7176
rand = new Random();
7277
// The code below generates no more than 12 random numbers and stores them into the account number

src/com/company/Main.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*The code below create 1 bank account for 1 person
2+
* and allows them to:
3+
* 1. Create a bank account
4+
* 2. Make an initial deposit
5+
* 3. Make a withdrawal
6+
* 4. Make multiple transactions */
7+
18
package com.company;
29

310
import java.util.InputMismatchException;
@@ -31,18 +38,25 @@ public static void main(String[] args) {
3138

3239
System.out.println("Account balance: " + newAccount.getBalance());
3340
}
34-
} catch (InputMismatchException e) {
35-
System.out.println("Invalid entry. Must input an integer value.");
41+
} catch (InputMismatchException e1) { //If the user inputs a value that either isn't an integer or is too big of an integer
42+
System.out.println("Invalid entry. Must input a valid integer value.");
43+
invalid = true;
44+
} catch (Exception e2){ //Catches all other exceptions
45+
System.out.println("Invalid entry.");
3646
invalid = true;
3747
}
3848

39-
System.out.println("Would you like to make another transaction? (Y/N)");
40-
String answer = scan.nextLine();
41-
if(answer.equalsIgnoreCase("Y") || answer.equalsIgnoreCase("YES")){
42-
continue;
43-
} else {
44-
break;
49+
// Ask the user this only if invalid is false, otherwise, if invalid is true, exit program
50+
if (invalid == false) {
51+
System.out.println("Would you like to make another transaction? (Y/N)");
52+
String answer = scan.nextLine();
53+
if(answer.equalsIgnoreCase("Y") || answer.equalsIgnoreCase("YES")){
54+
continue;
55+
} else {
56+
break;
57+
}
4558
}
59+
4660
}while(!invalid);
4761

4862
newAccount.showAccountDetails();

src/com/company/Person.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*You can create an ArrayList of BankAccounts
2+
* and give each person one
3+
* Using a foreach person print bank account info in main method*/
4+
15
package com.company;
26

37
public class Person {

0 commit comments

Comments
 (0)