ok so i have 3 separate classes: Product, Action, and Invoice. Action would be my interface that allows me to add and remove items in my hashmap that is in my Invoice class. my Product class would have the instance variables name, info, id and quantity (correct me if I'm wrong, I should have these as private variables). Also in my Product class are my getters and setters getID etc. Now I am kind of confused on how to add items into my hashmap with ID being the key and name info and quantity being the values.

public class Invoice implements Action<Product> {
private HashMap<Integer, Product> prod = new HashMap<Integer, Product>( );


  public void addProd(Product a) {
  // confused here
	  prod.put(getID(),??);
  }  
}

how to add items into my hashmap with ID being the key and name info and quantity being the values.

To have more than one item as the value, you will have to create a new class to hold all of the data items.
Does the Product object hold the data items you want to associate with the key in the HashMap? You have 90% of the code. Replace the ?? with a

Is there a way to do this without making any new class? and I don't think the getID() work either because I get an error saying getID() part is right either. I get the error saying method getID() is undefined for the class. The getID() method is from my Product class

Is there a way to do this without making any new class?

If you are trying to use the HashMap class's put method, you need to read the API doc for that method. What are the arguments for the put method?

What is the key and what is the value for what you want to put in the hashmap?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.