Two quickA few random notes:
- Floating point values are not precise. You should use
BigDecimals for the balance instead of double. Some useful reading:
-
private String error; // String the error from the exception
{
error = "error";
}
Lots of methods calls each other recursively. Some possible code paths:
menu -> query -> menu
query -> cardNumbers -> checkNumber -> contC2 -> menu
If a user uses the application long enough they will get a StackOverflowError sooner or later. You should use loops to get the user's input and don't call again recursively the menu printer method from the input handler.
A possible main menu method:
while (true) {
print main menu
read input
if input invalid {
continue
}
handle input (call submenu methods)
}
A possible submenu method:
while (true) {
print submenu
read input
if input invalid {
continue
}
if user chose exit submenu {
return
}
handle input
}
BankMain create new Scanners in every method although it already has one in its input field.
-
private String error; // String the error from the exception
{
error = "error";
}
The following is the same:
private String error = "error";
invalidAmount should be InvalidAmountException (Effective Java, 2nd Edition, Item 56: Adhere to generally accepted naming conventions)
-
ArrayList<Integer> cardNum = new ArrayList<Integer>();
should be
List<Integer> cardNum = new ArrayList<Integer>();
(Effective Java, 2nd edition, Item 52: Refer to objects by their interfaces)
Comments like this are really hard to read on smaller screens because of the horizontal scrolling and the unnecessary spaces:
private static void checkNumber(int num) throws invalidNumber //run the check activation exception
You could put it above the method declaration.
-
if (totalBal - withdrawAmount < 0) {
throw new invalidAmount("\n***ERROR!!! Insufficient funds in you accout***");
} else {
totalBal = totalBal - withdrawAmount;
availableBal = availableBal - withdrawAmount;
System.out.println("\n***Please take your money now...***");
}
If you throw an exception the else block is unnecessary, it could be this:
if (totalBal - withdrawAmount < 0) {
throw new invalidAmount("\n***ERROR!!! Insufficient funds in you accout***");
}
totalBal = totalBal - withdrawAmount;
availableBal = availableBal - withdrawAmount;
System.out.println("\n***Please take your money now...***");
It's often called as guard clause.