Answer:
public class CombinationLock {
private int combinationNumber1 = 0;
private int combinationNumber2 = 0;
private int combinationNumber3 = 0;
CombinationLock(int combinationNumber1, int combinationNumber2, int combinationNumber3){
this.combinationNumber1 = combinationNumber1;
this.combinationNumber2 = combinationNumber2;
this.combinationNumber3 = combinationNumber3;
}
public boolean open(int number1, int number2, int number3){
if(number1 == combinationNumber1 && number2 == combinationNumber2 && number3 == combinationNumber3)
return true;
else
return false;
}
public boolean changeCombo(int number1, int number2, int number3, int newNumber1, int newNumber2, int newNumber3){
if (open(number1, number2, number3)){
combinationNumber1 = newNumber1;
combinationNumber2 = newNumber2;
combinationNumber3 = newNumber3;
return true;
}else
return false;
}
}
Explanation:
- <em>Three variables</em> are created to hold the combination.
- A <em>constructor</em> is created to set the combination.
- A boolean method called <em>open</em> is created to check if the given numbers are correct, and <u>returns true</u> (<u>otherwise returns false</u>).
- A boolean method method called <em>changeCombo</em> is created to check if given numbers are correct. If they are correct, it assigns new values for the combination and <u>returns true</u> (<u>otherwise returns false</u>).