Подскажите, чем реализованный мной метод не верен? Ведь все работает, я специально тестировал
package com.javarush.task.pro.task10.task1010;
import java.util.Objects;
/*
Два айфона
*/
public class Iphone {
private String model;
private String color;
private int price;
public Iphone(String model, String color, int price) {
this.model = model;
this.color = color;
this.price = price;
}
//напишите тут ваш код
public boolean equals(Object object) {
if(object == null || getClass() != object.getClass())
return false;
if(this == object)
return true;
if(!(object instanceof Iphone))
return false;
Iphone iphone = (Iphone) object;
if(this.price != iphone.price)
return false;
if(this.model == null)
return iphone.model == null;
if(this.color == null)
return iphone.color == null;
return this.color.equals(iphone.color) && this.model.equals(iphone.model);
}
public static void main(String[] args) {
Iphone iphone1 = new Iphone("X", "Black", 999);
Iphone iphone2 = new Iphone("X", "Black", 999);
System.out.println(iphone1.equals(iphone2));
}
}