Home Ask Login Register

Developers Planet

Your answer is one click away!

Ahmed February 2016

How to display menu after input verification?

Main Class:

package BankingSystem;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Bank {

  public static void main (String [] args){

      //User verifies Account
        SignIn Valid = new SignIn(); 
        Scanner choice = new Scanner (System.in);  //allow user to choose menu option 

        int option = 0; //Menu option is set to 0 

                   // Menu For User 

            System.out.println("1:Deposit Cash");
            System.out.println("2: Withdraw Cash");
            System.out.println("3: View Current Account Balance");
            System.out.println("4: View Saving Account Balance");

            System.out.println("5: Cancel"); //When the User Quits the system prints out GoodBye

            System.out.println("Please choose");
            option= choice.nextInt();  

  }while (option < 6);



package BankingSystem;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class SignIn {
    public void AccountLogin (){
          List<String> AccountList = new ArrayList<String>(); 

          Scanner AccountInput = new Scanner(System.in);
         System.out.println("What is your account number?"); 
          boolean isExist = false; 

          for  (String item : AccountList){
              if (AccountInput.equals(AccountList.get(0))){
                  isExist = true;


          if (isExist){
              //Found In the ArrayList


I am trying to create a reasonably complex Banking System. In here at the start I intend the user to in


bedbad February 2016

You have the same mistake here as in your other questions.


You are comparing instance of class java.lang.String to the instance of class java.util.Scanner. You meant:


This will work and you will be able to match account number to the element of ArrayList(not the List itself, as u wrote)

All classes in Java derived from class Object (java.lang.Object). So you may not receive an Exception sometimes, because they have different signature. Sometimes they can be equal even though they are not equal in any common sense. In good times u will receive an Exception that will crash your program.

Generally you need to make sure that you are not comparing apples to oranges.

Its very easy to check: just look at the declarations of what it is you are comparing

Orange or1, or2;
Apple ap1;
or1.equals(ap1)     // BAD
or1.equals(or2)     // Good if equals() implemented for class Orange in
                    // in the way it satisfies you. 

Post Status

Asked in February 2016
Viewed 1,520 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life