Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import java.math.BigDecimal;
- import java.util.Objects;
- public class Product {
- private String barcode;
- private String name;
- private BigDecimal price;
- public Product(){
- barcode = "Barcode";
- name = "Name";
- price = BigDecimal.ZERO;
- }
- public Product(String barcode, String name, String price){
- this.barcode = barcode;
- this.name = name;
- this.price = new BigDecimal(price);
- }
- public String getBarcode(){
- return barcode;
- }
- public void setBarcode(String barCode){
- this.barcode = barCode;
- }
- public String getName(){
- return name;
- }
- public void setName(String name){
- this.name = name;
- }
- public BigDecimal getPrice(){
- return price;
- }
- public void setPrice(BigDecimal price){
- this.price = price;
- }
- public void setPrice(String price){
- this.price = new BigDecimal(price);
- }
- @Override
- public boolean equals(Object obj){
- if(obj == null) return false;
- if(obj == this) return true;
- if(obj.getClass() != this.getClass()) return false;
- final Product tmp = (Product) obj;
- return tmp.getBarcode().equals(this.getBarcode());
- }
- @Override
- public int hashCode(){
- return Objects.hash(barcode);
- }
- @Override
- public String toString(){
- return "\n-------------------------------" +
- "\n|Product|" +
- "\nBarcode: " + barcode +
- "\nName: " + name +
- "\nPrice: " + price +
- "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement