Tested this code from an exercise book and I don't understand why it refuses to compile because of "Incompatible types"
The version of Java is 7 update 51 and I am using a college computer so I suspect it is not a problem with versions or hardware.
There is something else going on, but I can't seem to figure it out.
The problem is at line 40 where the getState()
method returns a String for a switch
that has String cases. Incompatible.
I'd love to know what the machine is trying to do. Any help is greatly appreciated. Thank you so much for your time in advance.
public class AutoPolicy {
private int accountNumber;
private String makeAndModel, state;
public AutoPolicy(int accountNumber, String makeAndModel, String state) {
this.accountNumber = accountNumber;
this.makeAndModel = makeAndModel;
this.state = state;
}
public void setAccountNumber(int accountNumber) //Start set and get
{
this.accountNumber = accountNumber;
}
public int getAccountNumber() {
return accountNumber;
}
public void setMakeAndModel(String makeAndModel) {
this.makeAndModel = makeAndModel;
}
public String getMakeAndModel() {
return makeAndModel;
}
public void setState(String state) {
this.state = state;
}
public String getState() {
return state;
}
public boolean isNoFaultState() {
boolean noFaultState;
switch (getState()) {
case "MA":
case "NJ":
case "NY":
case "PA":
noFaultState = true;
break;
default:
noFaultState = false;
}
return noFaultState;
}
}