When I run the program, it says true. if I change one of the parameters for one of the Iphones, I get false, yet I am not meeting the second criteria?
package en.codegym.task.pro.task10.task1010;
import java.util.Objects;
/*
Two iPhones
*/
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 ob) {
if(this == ob)
return true;
if(!(ob instanceof Iphone))
return false;
Iphone iphone = (Iphone) ob;
if(this.equals(null) || iphone.color.equals(null) || iphone.model.equals(null))
return false;
return this.model.equals(iphone.model) && this.color.equals(iphone.color) && this.price == iphone.price;
}
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));
}
}