Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
added 2700 characters in body
Source Link
palacsint
  • 30.4k
  • 9
  • 82
  • 157

Two quickA few random notes:

  1. Floating point values are not precise. You should use BigDecimals for the balance instead of double. Some useful reading:
  1.  private String error; // String the error from the exception
     {
         error = "error";
     }
    
  1. 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
    }
  1. BankMain create new Scanners in every method although it already has one in its input field.

  2.  private String error; // String the error from the exception
     {
         error = "error";
     }
    

The following is the same:

    private String error = "error";
  1. invalidAmount should be InvalidAmountException (Effective Java, 2nd Edition, Item 56: Adhere to generally accepted naming conventions)

  2.  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)

  3. 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.

  1. 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.

Two quick notes:

  1. Floating point values are not precise. You should use BigDecimal for the balance instead of double. Some useful reading:
  1.  private String error; // String the error from the exception
     {
         error = "error";
     }
    

The following is the same:

    private String error = "error";

A few random notes:

  1. Floating point values are not precise. You should use BigDecimals for the balance instead of double. Some useful reading:
  1. 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
    }
  1. BankMain create new Scanners in every method although it already has one in its input field.

  2.  private String error; // String the error from the exception
     {
         error = "error";
     }
    

The following is the same:

    private String error = "error";
  1. invalidAmount should be InvalidAmountException (Effective Java, 2nd Edition, Item 56: Adhere to generally accepted naming conventions)

  2.  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)

  3. 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.

  1. 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.

Source Link
palacsint
  • 30.4k
  • 9
  • 82
  • 157

Two quick notes:

  1. Floating point values are not precise. You should use BigDecimal for the balance instead of double. Some useful reading:
- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
  1.  private String error; // String the error from the exception
     {
         error = "error";
     }
    

The following is the same:

    private String error = "error";