EldiraSesto

HardwareComponent

Mar 18th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package model;
  2.  
  3. import java.util.Objects;
  4.  
  5. public abstract class HardwareComponent { //Eldira Sesto, 11815163
  6.     private String id;
  7.     private float price;
  8.  
  9.     public HardwareComponent(String id, float price) {
  10.         this.id = id;
  11.         this.price = price;
  12.     }
  13.  
  14.     public String getId() {
  15.         return id;
  16.     }
  17.  
  18.     public void setId(String id) {
  19.         this.id = id;
  20.     }
  21.  
  22.     public float getPrice() {
  23.         return price;
  24.     }
  25.  
  26.     public void setPrice(float price) {
  27.         this.price = price;
  28.     }
  29.  
  30.     @Override
  31.     public boolean equals(Object o) {
  32.         if (this == o) return true;
  33.         if (o == null || getClass() != o.getClass()) return false;
  34.         HardwareComponent that = (HardwareComponent) o;
  35.         return Float.compare(that.getPrice(), getPrice()) == 0 &&
  36.                 getId().equals(that.getId());
  37.     }
  38.  
  39.     @Override
  40.     public String toString() {
  41.         return getId() + " (" + getPrice() + ") ";
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment