Advertisement
EldiraSesto

rbvs.product Product

Apr 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. package rbvs.product;
  2.  
  3. import ict.basic.IDeepCopy;
  4.  
  5. import java.util.Objects;
  6. //Eldira Sesto, 11815163
  7. public abstract class Product implements IProduct {
  8.  
  9.     private String name;
  10.     private float price;
  11.  
  12.     public Product(String name) {
  13.         this.name = name;
  14.     }
  15.  
  16.     public Product(String name, float price) {
  17.         this.name = name;
  18.         this.price = price;
  19.     }
  20.  
  21.     @Override
  22.     public String getname() {
  23.         return this.name;
  24.     }
  25.  
  26.     @Override
  27.     public float getPrice() {
  28.         return this.price;
  29.     }
  30.  
  31.     public void setName(String name) {
  32.         this.name = name;
  33.     }
  34.  
  35.     public void setPrice(float price) {
  36.         this.price = price;
  37.     }
  38.  
  39.     @Override
  40.     public abstract IDeepCopy deepCopy();
  41.  
  42.     @Override
  43.     public final boolean equals(Object o) {
  44.         if (this == o) return true;
  45.         if (o == null || getClass() != o.getClass()) return false;
  46.         Product product = (Product) o;
  47.         return Objects.equals(name, product.name);
  48.     }
  49.  
  50.     private void initialize (String name, float price){
  51.         if(name == null){
  52.             this.name = "";
  53.         }else {
  54.             this.name = name;
  55.         }
  56.  
  57.         this.price = price;
  58.     }
  59.  
  60.     @Override
  61.     public String toString() {
  62.         return "Product[" +
  63.                 "name='" + name + ',' +
  64.                 "price=" + price +
  65.                 ']';
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement