может, я условие задачи не понимаю, если модель и цвет у двух экземплярах класса будут "null", а прайс одинаковый, то метод должен вернуть "true"?
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;
}
@Override
//напишите тут ваш код
public boolean equals(Object obj){
if (this == obj){
return true;
}
if (obj == null){
return false;
}
if (!(obj instanceof Iphone)){
return false;
}
Iphone iphone = (Iphone) obj;
if (this.price != iphone.price){
return false;
}
if ((this.model == null) && (this.color == iphone.color)){
//System.out.println("w");
return iphone.model == null;
}
if ((this.color == null) && (this.model == iphone.model)){
//System.out.println("ww");
return iphone.color == null;
}
//System.out.println("www");
if ((this.model == null) && (this.color == null) && (iphone.color != null)){
return false;
}
if ((this.color == null) && (this.model == null) && (iphone.model != null)){
return false;
}
//System.out.println("wwww");
return this.model.equals(iphone.model) && this.color.equals(iphone.color);
}
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));
}
}