So I have been given a practice question that asks to write a method that compares the String verificationCode to the String secretKey character buy character. The int claimValue must also match. It should return true if the characters match and false if they don't.
The code compiles fine. But no matter what tests I run it always returns false. Could someone guide me where I'm going wrong?
public boolean verifyWin(int claimValue, String verificationCode, String secretKey) {
int prize = 0;
for (int i = 1; i <= verificationCode.length(); i++) {
if (verificationCode.charAt(i - 1) == secretKey.charAt(i - 1)) {
prize = prize + 1;
} else {
prize = prize - 1;
}
}
if (prize == claimValue) {
return true;
} else {
return false;
}
}
The tests are:
//Test (1):
Lottery winner = new Lottery();
winner.setVerificationCode("HHHHHH");
winner.setSecretKey("HHHHHH");
winner.setClaimValue(1);
winner.verifyWin(1 , "HHHHHH", "HHHHHH");
returns false
//Test 2
Lottery winner = new Lottery();
winner.setVerificationCode("HHHH44");
winner.setSecretKey("HHHH44");
winner.setClaimValue(1);
winner.verifyWin(1 , "HHHH44", "HHHHH44");
returns false