Question: PLEASE ANS IN JAVA How would I access an attribute of a specific object if the object is key in a Hashmap? In the example

PLEASE ANS IN JAVA

How would I access an attribute of a specific object if the object is key in a Hashmap? In the example below I want to access the Id attribute which is in my object Product from my hashmap key. Please let me know if I don't make sense and I can rephrase my question.

PLEASE ANS IN JAVA How would I access an attribute of aspecific object if the object is key in a Hashmap? In the

public class Product { private String name; private int Id; private double price; public Product(String Name, int Id, double Price) { this.name = Name; this.Id = ID; this.price = Price; } A //Getter Methods public String getName() {return name;} public int getId() {return Id;} public double getPrice() {return price;} } public class Inventory2 { //Var Declarations private int quantity; private Product type; private Map inut = new HashMap(); public Inventory2(int Quantity, Product Type, HashMap Invt) { this.quantity = Quantity; this.type = Type; this.invt = Invt; } public void setType (Product type){this.type type;} public void setInut (Map invt) {this.invt invt;} public void setQuantity(int quantity) { this.quantity quantity;} public int getQuantity(){return quantity;} public Product getType(){return type;}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!