Question: Please help to correct so this below Java code compile and ryn properly, and please send the code back with the changes in the code

Please help to correct so this below Java code compile and ryn properly, and please send the code back with the changes in the code in whole. 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;
}
}
abstract class Player {
protected String name;
public Player(String name){
this.name = name;
}
public abstract int makeMove(int currentSticks);
}
class Computer extends Player {
public Computer(String name){
super(name);
}
@Override
public int makeMove(int currentSticks){
int sticks =1+(int)(Math.random()*(currentSticks /2));
System.out.println(name +" takes "+ sticks +" sticks.");
return sticks;
}
}
class NimGame {
private int sticks;
private Player player1;
private Player player2;
public NimGame(int sticks){
this.sticks = sticks;
this.player1= new Computer("Computer");
this.player2= new Human("Human");
}
public void startGame(){
Player currentPlayer = player1;
while (sticks >1){
System.out.println("Current sticks: "+ sticks);
int takenSticks = currentPlayer.makeMove(sticks);
sticks -= takenSticks;
if (sticks <=1){
System.out.println("No moves left. "+ currentPlayer.name +" wins!");
break;
}
currentPlayer =(currentPlayer == player1)? player2 : player1;
}
}
}
public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int sticks = scanner.nextInt();
if (args.length >0){
int initialSticks = Integer.parseInt(args[0]);
NimGame game = new NimGame(initialSticks);
game.startGame();
} else {
System.out.println("Please provide the initial number of sticks as a command-line argument." + 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!