Need help removing item from Bag Array. I can't seem to compare the information in a new Object created to the one in the Bag Array I built.
This is a method that lives inside of my ADT Bag.
public boolean removeParticular(T item) { checkIntegrity(); int index = getIndexOf(item); T result = removeEntry(index); System.out.println(item.equals(result)); return item.equals(result); }
I created this public method in the main to test out my Bag removeParticular(T item)
public static void removeItem() { System.out.println("Choose item to remove."); clothing tempClothing = new clothing("red shirt", 23.22); bag.removeParticular(tempClothing); bag.display(); }
Unfortunately it continues to come up false and not remove the item that has matching values to the created instance. I'm new to Bags in Java so I'm not sure if there is another way I need to pass the item Object through besides creating a completely new object with identical values.
Also this
private T removeEntry(int i) { T result = null; if(!isEmpty() && (i > 0)) { result = clothingArray\[i\]; clothingArray\[i\] = clothingArray\[numOfItems - 1\]; clothingArray\[numOfItems - 1\] = null; numOfItems--; } return result; }
private int getIndexOf(T item) { int where = -1; boolean found = false; int i = 0; while (!found && (i < numOfItems)) { if(item.equals(clothingArray\[i\])) { found = true; where = i; } else { i++; }} return where; }
submitted by /u/OutlandishnessOdd692
[link] [comments]
from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/hC4iPtO