Question: (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?)
import java.util.ArrayList; import java.util.Scanner;
public class Accounts { static ArrayList
public static void add() { System.out.print("Enter acc no : "); String number = scanner.next(); accounts.add(number); }//closes add method
public static void overwrite() { System.out.print("Enter acc no : "); String number = scanner.next(); int accPos = -1; for (int i = 0; i < accounts.size(); i++) { if (accounts.get(i).equalsIgnoreCase(number)) { accPos = i; } } if (accPos == -1) { System.out.println("No Account is present with given number"); return; } else { System.out.print("Enter new acc no : "); String newAccNumber = scanner.next(); accounts.set(accPos, newAccNumber); System.out.println("Successfully overwrite"); } }//closes overwrite method
public static void remove() { System.out.print("Enter acc no : "); String number = scanner.next(); if (accounts.remove(number)) { System.out.println("Successfully removed"); } else { System.out.println("Account not present"); } }//closes remove method
public static void display() { System.out.println("Accounts :"); for (String number : accounts) { System.out.println(number); } }//closes display method
}//closes Accounts class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
