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;
}
}
Step-by-step explanation:
- Three variables are created to hold the combination.
- A constructor is created to set the combination.
- A boolean method called open is created to check if the given numbers are correct, and returns true (otherwise returns false).
- A boolean method method called changeCombo is created to check if given numbers are correct. If they are correct, it assigns new values for the combination and returns true (otherwise returns false).