I'm having issues removing class objects from an arraylist in a class.
package more_java;
import java.util.ArrayList;
public class PiggyBank {
private static ArrayList<Coin> coins = new ArrayList<Coin>();
public PiggyBank(ArrayList<Coin> coins) {
PiggyBank.coins = coins;
}
public static void addNickel(){coins.add(new Nickel());}
public static void addDime(){coins.add(new Dime());}
public static void addQuarter(){coins.add(new Quarter());}
public static void addLoonie(){coins.add(new Loonie());}
public static void addToonie(){coins.add(new Toonie());}
public static void removeNickel() {coins.remove(Nickel());}
public static void removeDime(){coins.remove(Dime());}
}
Nickel, Dime, Quarter, Loonie, and Toonie are all class objects made as extensions of an abstract class Coin. Each of these coins contain nothing but an accessor method GetValue()
which simply returns the value of each coin. The problem comes from the remove methods where I get the error: The method Nickel() is undefined for the type PiggyBank
. Any help would be much appreciated.