java - cannot find symbol errors -


i'm bit lost; feel i've done things similar before, doesn't work. there adjustment i'm forgetting? reason it's saying can't find 3 variables below, need move them elsewhere/declare in method/somehow disjoint method variable call? appreciated.

scanner input = new scanner(system.in);         int atmid, selection;         double atmval;     selectid();          switch(selection){             case 1:  accarray[atmid].getbalance();                     break;             case 2: system.out.print("how withdraw? ");                     atmval=input.nextint();                     accarray[atmid].withdraw(atmval);                      break;             case 3:  system.out.print("how deposit? ");                     atmval=input.nextint();                     accarray[atmid].deposit(atmval);                     break;              case 4:  selectid();                     break;         }       } // end of main method  // method id selection     public static void selectid(){ // allows , requests user input                system.out.print("enter id: ");         atmid = input.nextint();  // checks valid input                while (atmid>9 || atmid<0){             system.out.println("invalid id.");             system.out.print("enter id (0-9): ");             atmid = input.nextint();         }         displaymenu();     }  // method display menu     public static void displaymenu(){         system.out.println("main menu");         system.out.println("1: check balance");         system.out.println("2: withdraw");         system.out.println("3:deposit");         system.out.println("4:exit");         system.out.print("enter choice ");         selection = input.nextint();         // checks valid input          while (selection>4 || selection<1){             system.out.println("invalid choice.");             system.out.print("enter choice (1-4): ");             selection = input.nextint();         }     } } // end of test class 

note have scoping errors -- variables declared inside of method visible within method , not visible in other methods. solve this, declare variables within class.

for example, using static fields , methods:

public class foo {   private static int bar; // visible throughout class    public static void somemethod() {     int baz = 8;  // i've declared *local* variable here   }    public static void anothermethod() {     bar = 3;  // can use bar here since it's visible throughout      baz = 7; // won't compile since baz visible within somemethod()   } } 

having said that, though shouldn't selectid() method return int? shouldn't assign returned int selection variable? if did this, selection variable not have declared in class.

note have displaymenu() -- display menu, , not have user input. selectid() method do.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -