guys and/or gals. I'm having some trouble with this programming assignment for my Programming 2 class. I feel a bit ashamed that I'm so lost since I seemed to excel in the prior class. I apologize in advance for what is most likely a trivial problem, but I'm having trouble applying any solutions I find online to my specific code. Long story short, I've got a Car constructor that has two strings for a make and model (i.e. Honda, civic, respectively).
public Car(String make, String model, double basePrice, String plateNum)
{
this.make = make;
this.model = model;
this.basePrice = basePrice;
this.plateNum = plateNum;
}
In order for the equals method to function, the cars must have the same make and model. Here's what I keep messing with, but it always returns false.
@Override
public boolean equals(Object other)
{
if(!(other instanceof Car))
return false;
Car temp = (Car)other;
if(this.equals(temp.getMake()) && this.equals(temp.getModel()))
return true;
else
return false;
}
I've tried it without the "not" in front of the instanceof if statement, and I've tried inverting the this and temp, to no avail. I know giving out answers to homework is frowned upon, and I understand it completely. If not, perhaps someone could be kind enough to explain what I'm doing wrong? I'm not entirely sure what "this" means. I imagine that it is essentially a placeholder for what will be calling the method. In this case, it would be a CarObject.equals.
Anyway, thank you again in advance. This website has helped me out many times in the past, I'm looking forward to any replies. :)