Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package application;
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.Objects;
  5.  
  6. public class Product {
  7.     private String barcode;
  8.     private String name;
  9.     private BigDecimal price;
  10.  
  11.     public Product(){
  12.         barcode = "Barcode";
  13.         name = "Name";
  14.         price = BigDecimal.ZERO;
  15.     }
  16.  
  17.     public Product(String barcode, String name, String price){
  18.         this.barcode = barcode;
  19.         this.name = name;
  20.         this.price = new BigDecimal(price);
  21.     }
  22.  
  23.     public String getBarcode(){
  24.         return barcode;
  25.     }
  26.  
  27.     public void setBarcode(String barCode){
  28.         this.barcode = barCode;
  29.     }
  30.  
  31.     public String getName(){
  32.         return name;
  33.     }
  34.  
  35.     public void setName(String name){
  36.         this.name = name;
  37.     }
  38.  
  39.     public BigDecimal getPrice(){
  40.         return price;
  41.     }
  42.  
  43.     public void setPrice(BigDecimal price){
  44.         this.price = price;
  45.     }
  46.  
  47.     public void setPrice(String price){
  48.         this.price = new BigDecimal(price);
  49.     }
  50.  
  51.     @Override
  52.     public boolean equals(Object obj){
  53.         if(obj == null) return false;
  54.         if(obj == this) return true;
  55.         if(obj.getClass() != this.getClass()) return false;
  56.         final Product tmp = (Product) obj;
  57.         return tmp.getBarcode().equals(this.getBarcode());
  58.     }
  59.  
  60.     @Override
  61.     public int hashCode(){
  62.         return Objects.hash(barcode);
  63.     }
  64.  
  65.     @Override
  66.     public String toString(){
  67.         return  "\n-------------------------------" +
  68.                 "\n|Product|" +
  69.                 "\nBarcode: " + barcode +
  70.                 "\nName: " + name +
  71.                 "\nPrice: " + price +
  72.                 "\n";
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement