The method add() in the type ArrayList<r> is applicable for the arguments(int,product)

HI, I am having trouble getting my arraylist to work. I am trying to pass an object from the main method through the ComputerOrder subclass to the "add" method in GenericOrder. I also want to have an id be associated with the product being passed to the add method and put in an arraylist. However, I keep getting the error message "The method add(int, GenericOrder) in the type ArrayList<GenericOrder> is not applicable for the
 arguments (int, Product)" In Eclipse. Any advice would be appreciated. Thanks.
class GenericOrder
{
	private static int OrderNumber = 1000;
	private final int id = OrderNumber ++;
	private ArrayList<GenericOrder> Product = new ArrayList<GenericOrder>();
    public void add(Product p){
    	Product.add(id,p); <--error message here.
    	
    	
    }
	
}
	
@SuppressWarnings("serial")
class ComputerOrder extends GenericOrder{
	
	@Override
	public void add(Product p) {
		if(p instanceof ComputerPart || p instanceof Peripheral || p instanceof Service) 
			super.add(p);
		else System.out.println("error");
		// TODO Auto-generated constructor stub
	}
	
}
 
@SuppressWarnings("serial")
class PartyTrayOrder extends GenericOrder{
	
	@Override
	public void add(Product p){
		if(p instanceof Cheese || p instanceof Fruit || p instanceof Service)
			super.add(p);
		 else System.out.println("error");
	}
 
}
 
class OrderProcessor{
	
	ArrayList<GenericOrder> products = new ArrayList<GenericOrder>();
	ArrayList<Peripheral> peripheral = new ArrayList<Peripheral>();
	ArrayList<Service> service = new ArrayList<Service>();
	ArrayList<Fruit> fruit = new ArrayList<Fruit>();
	ArrayList<Cheese> cheese = new ArrayList<Cheese>();
	
   public static void main(String[] args){
	   
   	Drive d = new Drive("Seagate",3,300);
   	Product p = d;
   	ComputerOrder order = new ComputerOrder();
   	order.add(p);

Open in new window

grnmachineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cmalakarCommented:
ArrayList is a data type to hold only list of objects..

It cannot store a pair of objects in each position...

You can use.. Map Collections which stores "key, value" pairs...
0
Ajay-SinghCommented:
Is Product a class?
0
cmalakarCommented:
>> I keep getting the error message "The method add(int, GenericOrder) in the type ArrayList<GenericOrder> is not applicable for the arguments (int, Product)

This error message is thrown, when your arraylist is declared for objects of one type and you are trying to add objects of another type.

ie., arraylist is declared to be a list of GenericOrder objects...

>> ArrayList<GenericOrder> Product = new ArrayList<GenericOrder>()

but you are trying to add an object of type "Product"

>> Product.add(id,p);

0
oleberCommented:
Lets try to see what is happing

private ArrayList<GenericOrder> Product = new ArrayList<GenericOrder>();

You are creating a ArrayList that will just accept GenericOrder or sub class of GenericOrder objects. This seems wrong.



Your problem seems to be in the design to code.

You shall have a Base class for the products, for example Product. After each kind of product that you have shall derive from Product.

In the GenericOrder class you will have

private ArrayList<Product> products = new ArrayList<Product>();

now you can have your method

public void add(Product p){
        products.add(id,p);
}

Is this clear
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.