Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 HumanString name
supername;
scanner new ScannerSystemin;
@Override
public int makeMoveint currentSticks
System.out.printlnname enter number of sticks to take to currentSticks : ;
int sticks scanner.nextInt;
while sticks sticks currentSticks
System.out.printlnInvalid number of sticks. Try again: ;
sticks scanner.nextInt;
return sticks;
abstract class Player
protected String name;
public PlayerString name
this.name name;
public abstract int makeMoveint currentSticks;
class Computer extends Player
public ComputerString name
supername;
@Override
public int makeMoveint currentSticks
int sticks intMathrandomcurrentSticks ;
System.out.printlnname takes sticks sticks.";
return sticks;
class NimGame
private int sticks;
private Player player;
private Player player;
public NimGameint sticks
this.sticks sticks;
this.player new ComputerComputer;
this.player new HumanHuman;
public void startGame
Player currentPlayer player;
while sticks
System.out.printlnCurrent sticks: sticks;
int takenSticks currentPlayer.makeMovesticks;
sticks takenSticks;
if sticks
System.out.printlnNo moves left. currentPlayer.name wins!";
break;
currentPlayer currentPlayer player player : player;
public class Main
public static void mainString args
Scanner scanner new ScannerSystemin;
int sticks scanner.nextInt;
if argslength
int initialSticks Integer.parseIntargs;
NimGame game new NimGameinitialSticks;
game.startGame;
else
System.out.printlnPlease provide the initial number of sticks as a commandline argument." sticks;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started