Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.desktop.SystemEventListener;
- import java.util.HashSet;
- import java.util.Objects;
- public class Part {
- private String name;
- private String code;
- private PartType category;
- private HashSet<car> supportedCars;
- private double buyPrice;
- private double sellPrice;
- private Manufacturer manifacturer;
- public Part(String name, double buyPrice, double sellPrice,
- Manufacturer manifacturer,String code,PartType category){
- this.name=name;
- this.buyPrice=buyPrice;
- this.sellPrice=sellPrice;
- this.manifacturer= manifacturer;
- this.code=code;
- this.category=category;
- this.supportedCars=new HashSet<car>();
- }
- public void addSupportedCars(car cars){
- this.supportedCars.add(cars);
- }
- public String toString(){
- StringBuilder result= new StringBuilder();
- result.append("Part:" + this.name );
- result.append(System.lineSeparator());
- result.append("-code:" + this.code);
- result.append(System.lineSeparator());
- result.append("-category:" + this.category);
- result.append(System.lineSeparator());
- result.append("-buyPrice:" + this.buyPrice);
- result.append(System.lineSeparator());
- result.append("-sellPrice:" + this.sellPrice);
- result.append(System.lineSeparator());
- result.append("-manifacturer:" + this.manifacturer);
- result.append(System.lineSeparator());
- result.append("--Supported cars--");
- result.append(System.lineSeparator());
- for(car cars:this.supportedCars){
- result.append(cars);
- System.lineSeparator();
- }
- result.append("------------------");
- result.append(System.lineSeparator());
- return result.toString();
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Part part = (Part) o;
- return Double.compare(part.buyPrice, buyPrice) == 0 &&
- Double.compare(part.sellPrice, sellPrice) == 0 &&
- name.equals(part.name) &&
- code.equals(part.code) &&
- category.equals(part.category) &&
- supportedCars.equals(part.supportedCars) &&
- manifacturer.equals(part.manifacturer);
- }
- @Override
- public int hashCode() {
- return Objects.hash(name, code, category, supportedCars, buyPrice, sellPrice, manifacturer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement