Okay so I need to delete a bankAccount. Basically, I have a whole program that I
ID: 3558190 • Letter: O
Question
Okay so I need to delete a bankAccount. Basically, I have a whole program that I can add accounts to an array and deposit money in the accounts and withdraw money from the accounts etc. What i am trying to do now is set up a deleteAccount method in which I can delete any account in the array list. So the program will:
private static void createNewAccount(ArrayList list) {
int number = list.size() + 1;
String first = "", last = "";
first = nameCheck("first");
last = nameCheck("last");
System.out.print("Enter the initial balance: $");
BigDecimal initialBal = ammount();
BankAccount acc = new BankAccount(number, first, last, initialBal);
list.add(acc);
System.out.println("Thank You, " + first + " " + last + " for joining our bank today! Have a great Day!");
System.out.println("Your account no is " + number + " and initial balance is $" + new DecimalFormat("0.00").format(initialBal));
}
public static void deleteAccount(ArrayList list){
int number = list.size();
System.out.print("Enter the account number you want to delete: ");
list.remove(number);
}
If you need more of my code I can email it to you just send me an email at sluger233@gmail.com and I will be glad to send you the code.
Explanation / Answer
I am giving an example for removing an item from array list
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
// create an empty array list with an initial capacity
ArrayList<String> arrlist = new ArrayList<String>(5);
// use add() method to add values in the list
arrlist.add("G");
arrlist.add("E");
arrlist.add("F");
arrlist.add("M");
arrlist.add("E");
System.out.println("Size of list: " + arrlist.size());
// let us print all the values available in list
for (String value : arrlist) {
System.out.println("Value = " + value);
}
// Removes first occurrence of "E"
arrlist.remove("E");
System.out.println("Now, Size of list: " + arrlist.size());
// let us print all the values available in list
for (String value : arrlist) {
System.out.println("Value = " + value);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.