Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Need help with Game constructor method only . Looking for, input: none outp

ID: 3740906 • Letter: J

Question

Java Need help with Game constructor method only.  

Looking for,

input: none

output: none

1) create the two players and a pigDice

2) inintializes the current player to start the game and sets game over condition to false.

Thankyou,

import java.util.Scanner;

//******************************************************************************************

//

//

//******************************************************************************************

public class Game

{

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

private Player p1, p2, current;

private PigDice d;

private boolean gameOver;

private final int WINNING_SCORE = 100;

//---------------------------------------------------------------------------------------

// Game Constructor method

//---------------------------------------------------------------------------------------

public Game()

{

Scanner scan = new Scanner(System.in);

}

//---------------------------------------------------------------------------------------

// need details of PigDice to play game

//---------------------------------------------------------------------------------------

public boolean playGame()

{

}

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

public boolean gameOver()

{

return gameOver;

}

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

public Player getCurrentPlayer()

{

return p1;

}

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

public Player getHuman()

{

return p2;

}

//---------------------------------------------------------------------------------------

//

//---------------------------------------------------------------------------------------

public Player getComputer()

{

return getComputer;

}

//--------------------------------------------------------------------------------------

//

//--------------------------------------------------------------------------------------

public PigDice getPigDice()

{

return d;

}

//--------------------------------------------------------------------------------------

//

//--------------------------------------------------------------------------------------

public String toString()

{

return "Game{" +

"p1=" + p1 +

",p2=" + p2 +

",current=" + current +

", d=" + d +

",gameOver=" + gameOver +

",WINNER_SCORE=" + WINNER_SCORE + "}";

}

}

Explanation / Answer

import java.util.Scanner; //****************************************************************************************** // // //****************************************************************************************** public class Game { //--------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------- private Player p1, p2, current; private PigDice d; private boolean gameOver; private final int WINNING_SCORE = 100; //--------------------------------------------------------------------------------------- // Game Constructor method //--------------------------------------------------------------------------------------- public Game() { Scanner scan = new Scanner(System.in); p1 = new Player("Player") { @Override public boolean beAPig(boolean isPig) { return false; } }; p2 = new Player("Computer") { @Override public boolean beAPig(boolean isPig) { return false; } }; current = p1; } //--------------------------------------------------------------------------------------- // need details of PigDice to play game //--------------------------------------------------------------------------------------- public boolean playGame() { } //--------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------- public boolean gameOver() { return gameOver; } //--------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------- public Player getCurrentPlayer() { return p1; } //--------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------- public Player getHuman() { return p2; } //--------------------------------------------------------------------------------------- // //--------------------------------------------------------------------------------------- public Player getComputer() { return getComputer; } //-------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------- public PigDice getPigDice() { return d; } //-------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------- public String toString() { return "Game{" + "p1=" + p1 + ",p2=" + p2 + ",current=" + current + ", d=" + d + ",gameOver=" + gameOver + ",WINNER_SCORE=" + WINNER_SCORE + "}"; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote