Java - removing obj from ArrayList.

Status
Not open for further replies.

eNergy!.

Beta member
Messages
1
Hello,
Nice forum you've got here guys ;D

Anyway,
I noticed this section and realised I have a problem someone may be able to help me with.

I'm currently doing my CertIV in Programming (which leads into DB design), but anyway, I'm having problems removing an item from my ArrayList through a different method ( think that's the terminology?).

Oh, also; I can't edit the "ShoppingCartTest.java" file.

The error I get is:
removeItem() in ShoppingCart cannot be applied to (Product) -- at line 57

Here's some extracts from the code, hoping someone can help.
thanks!

--The Product constructor and ShoppingCart constructors are fine. :)

ShoppingCartTest.java
Code:
public class ShoppingCartTest extends TestCase
{
private ShoppingCart cart;
private Product book1;

cart = new ShoppingCart();
book1 = new Product("Pragmatic Unit Testing", 29.95);

public void testRemoveItem()
{
try
{
[COLOR="Red"]//line 57 cart.removeItem(book1);[/COLOR]
assertEquals(0, cart.getItemCount());
}
catch(ProductNotFoundException expected)
{
// successful test
System.out.println("\n Item not in cart");
}
}
}

ShoppingCart.java
Code:
public class ShoppingCart
{
public boolean removeItem()
{
return array.remove([COLOR="Red"]NOT SURE WHAT TO PUT IN HERE[/COLOR]);
}
}

Product.java
Code:
public class Product
{
private String prodName;
private double prodPrice;

public Product(String newProdName, double newProdPrice)
{ 
prodName = newProdName;
prodPrice = newProdPrice;
}
}

Hope someone can help with that.
I can always provide more of the code, I just didn't want to destroy the length of this post. [=
Thanks. :)
 
Status
Not open for further replies.
Back
Top Bottom