Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use one array on 2 different classes
    primarykey
    data
    text
    <p>I have 2 classes right now, the first class has the arraylist in it. But on the second class when I try to access the arraylist it keeps giving me the red line underneath saying that the variable doesn't exist. </p> <p>Here is class one...</p> <pre><code>public class BankMain { public static void main(String[] args) { // TODO Auto-generated method stub BankMain main = new BankMain(); menu(); } public static void cardNumbers(){ ArrayList&lt;Integer&gt; cardNum = new ArrayList&lt;Integer&gt;(); Scanner cards = new Scanner(System.in); Scanner input = new Scanner(System.in); Scanner keyboard = new Scanner(System.in); System.out.println("Please select a 5 digit card number"); cardNum.add(input.nextInt()); System.out.println("Thank you! You're card number is " +cardNum); System.out.println("Type 'c' to go back to main menu."); String value = keyboard.next(); if(value.equalsIgnoreCase("c")){ menu(); } else if (!keyboard.equals('c')){ System.out.println("Invalid Entry!"); } } public static void menu(){ System.out.println("What Would you like to do today?"); System.out.println(); System.out.println("Create Account = 1"); System.out.println("Login = 2"); System.out.println("Exit = 3"); query(); } public static void query(){ Scanner keyboard = new Scanner(System.in); double input = keyboard.nextInt(); if (input == 2){ BankMainPart2 main2 = new BankMainPart2(); System.out.println("Please enter your 5 digit card number."); main2.loginCard(); } else if (input == 1){ cardNumbers(); } else if (input == 3){ System.out.println("Thank you, have a nice day!"); System.exit(0); } } } </code></pre> <p>Here is the second class...</p> <pre><code>public class BankMainPart2 { public static void loginCard(){ if (cardNum.contains(name)) { } } } </code></pre> <p>I know I haven't entered anything in the if statement yet on the second class but I'm just trying to get my array list to work on both classes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload