私はこのコードを手に入れました:
System.out.println("Enter the brand and cash value");
String brand = keyboard.nextLine();
long cash = keyboard.nextDouble();
String buffer = keyboard.nextLine();
しかし、比較しようとしている正確な文字列値を入力しても、それらが同じであることを認識できません。不思議なことに、これを入力すると:
compare[0] = new Car ("BMW", 12.00);
これの代わりに:
compare[0] = new Car (brand, 12.00);
できます
私もequalsを使用します:
public boolean equals(Car other)
{
if (other == null)
{
return false;
}
if(this.brand == other.brand && this.cash == other.cash)
{
return true;
}
else
{
return false;
}
}