Question: Please help to explain in the below Java code if the move ( take a stick ) should be checked at the time of loading

Please help to explain in the below Java code if the move(take a stick) should be checked at the time of loading or can you wait until when the move is to be performed? Both solutions have advantages and disadvantages. Please tell what you prefer, how you did? import java.util.Scanner;
class Human extends Player {
private Scanner scanner;
public Human(String name){
super(name);
scanner = new Scanner(System.in);
}
@Override
public int makeMove(int currentSticks){
System.out.println(name +", enter number of sticks to take (1 to "+ currentSticks /2+"): ");
int sticks = scanner.nextInt();
while (sticks <1|| sticks > currentSticks /2){
System.out.println("Invalid number of sticks. Try again: ");
sticks = scanner.nextInt();
}
return sticks;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!