Advertisement
go6eto

part-class

Feb 18th, 2021
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. import java.awt.desktop.SystemEventListener;
  2. import java.util.HashSet;
  3. import java.util.Objects;
  4.  
  5. public class Part {
  6.     private String name;
  7.     private String code;
  8.     private PartType category;
  9.     private HashSet<car> supportedCars;
  10.     private double buyPrice;
  11.     private double sellPrice;
  12.     private Manufacturer manifacturer;
  13.  
  14.     public Part(String name, double buyPrice, double sellPrice,
  15.                 Manufacturer manifacturer,String code,PartType category){
  16.         this.name=name;
  17.         this.buyPrice=buyPrice;
  18.         this.sellPrice=sellPrice;
  19.         this.manifacturer= manifacturer;
  20.         this.code=code;
  21.         this.category=category;
  22.         this.supportedCars=new HashSet<car>();
  23.     }
  24.  
  25.     public void addSupportedCars(car cars){
  26.  
  27.         this.supportedCars.add(cars);
  28.     }
  29.  
  30. public String toString(){
  31.         StringBuilder result= new StringBuilder();
  32.         result.append("Part:" + this.name );
  33.         result.append(System.lineSeparator());
  34.  
  35.         result.append("-code:" + this.code);
  36.         result.append(System.lineSeparator());
  37.  
  38.         result.append("-category:" + this.category);
  39.         result.append(System.lineSeparator());
  40.  
  41.         result.append("-buyPrice:" + this.buyPrice);
  42.         result.append(System.lineSeparator());
  43.  
  44.         result.append("-sellPrice:" + this.sellPrice);
  45.         result.append(System.lineSeparator());
  46.  
  47.         result.append("-manifacturer:" + this.manifacturer);
  48.         result.append(System.lineSeparator());
  49.  
  50.     result.append("--Supported cars--");
  51.         result.append(System.lineSeparator());
  52.  
  53.         for(car cars:this.supportedCars){
  54.             result.append(cars);
  55.             System.lineSeparator();
  56.  
  57.         }
  58.         result.append("------------------");
  59.         result.append(System.lineSeparator());
  60.         return result.toString();
  61.     }
  62.  
  63. @Override
  64.     public boolean equals(Object o) {
  65.         if (this == o) return true;
  66.         if (o == null || getClass() != o.getClass()) return false;
  67.         Part part = (Part) o;
  68.         return Double.compare(part.buyPrice, buyPrice) == 0 &&
  69.                 Double.compare(part.sellPrice, sellPrice) == 0 &&
  70.                 name.equals(part.name) &&
  71.                 code.equals(part.code) &&
  72.                 category.equals(part.category) &&
  73.                 supportedCars.equals(part.supportedCars) &&
  74.                 manifacturer.equals(part.manifacturer);
  75.     }
  76.  
  77.     @Override
  78.     public int hashCode() {
  79.         return Objects.hash(name, code, category, supportedCars, buyPrice, sellPrice, manifacturer);
  80.     }
  81.  
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement