if (!(this.model.equals(iphone.model)) && !(this.color.equals(iphone.color)) && !(this.price==(iphone.price)))
{
b=false;
}
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;
}
//write your code here
public boolean equals(Object obj1)
{
if (this == obj1)
{
return true;
}
else if (obj1 == null)
{
return false;
}
else if (!(obj1 instanceof Iphone))
{
return false;
}
Iphone iphone = (Iphone) obj1;
boolean b=false;
if((this.model.equals(iphone.model)) && (this.color.equals(iphone.color)) && (this.price==(iphone.price)))
{
b=true;
}
if (!(this.model.equals(iphone.model)) && !(this.color.equals(iphone.color)) && !(this.price==(iphone.price)))
{
b=false;
}
if ((iphone.model==null) || (iphone.color==null))
{
b=false;
}
return b;
}
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));
}
}