package collections.hashset;
public class Product {
private int id; private String name;
private String descr;
private int qty;
private double priceEa;
private double priceNet;
public Product(int _id, String _name,
String _descr, int _qty, double _price) {
id = _id;
name = _name;
descr = _descr;
qty = _qty;
priceEa = _price;
priceNet = qty * priceEa;
}
public int hashCode() {
System.out.println("-- hashCode method called.");
return id;
}
public boolean equals(Object o) {
System.out.println("-- equals method called.");
if (o != null && o.getClass().equals(this.getClass()))
return (id == ((Product) o).getId());
return false;
}
public String toString() {
return "\nid:" + id +
"\nname=" + name +
"\ndescr=" + descr +
"\nqty=" + qty +
"\npriceEach=" + priceEa +
"\npriceNet=" + priceNet;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescr() {
return descr;
}
public int getQty() {
return qty;
}
public double getPriceEa() {
return priceEa;
}
public double getPriceNet() {
return priceNet;
}
}