java - 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();          valid.accountlogin();         scanner choice = new scanner (system.in);  //allow user choose menu option           int option = 0; //menu option set 0                       // menu user            do{             system.out.println("welcome");             system.out.println();             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 user quits system prints out goodbye              system.out.println("please choose");             option= choice.nextint();        }while (option < 6); }     } 

accountloginclass:

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>();            accountlist.add("45678690");            scanner accountinput = new scanner(system.in);          system.out.println("what account number?");            accountinput.next();            boolean isexist = false;              (string item : accountlist){               if (accountinput.equals(accountlist.get(0))){                   system.out.println("hi");                   isexist = true;                   break;                }            }            if (isexist){               //found in arraylist           }           }          } 

i trying create reasonably complex banking system. in here @ start intend user input account number matches array list , when match number in arraylist displayed menus i.e. withdraw, deposit etc.
problem here i’m not sure how can created object before menu linking accountloginclass, doesn’t work.

you have same mistake here in other questions.

accountinput.equals(accountlist.get(0)) 

you comparing instance of class java.lang.string instance of class java.util.scanner. meant:

(accountinput.nextline()).equals(accountlist.get(0)) 

this work , able match account number element of arraylist(not list itself, u wrote)

all classes in java derived class object (java.lang.object). may not receive exception sometimes, because have different signature. can equal though not equal in common sense. in times u receive exception crash program.

generally need make sure not comparing apples oranges.

its easy check: @ declarations of comparing

orange or1, or2; apple ap1; ... or1.equals(ap1)     // bad or1.equals(or2)     // if equals() implemented class orange in                     // in way satisfies you.  

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -