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

I need a main method to run this program, it needs to be in java. This is the co

ID: 3914001 • Letter: I

Question

I need a main method to run this program, it needs to be in java.

This is the code,

public class Pig
{   
public static void main(String args[]){
Pig game = new Pig();
}
private GVdie d1;
private GVdie d2;
private int computerScore;
private int playerScore;
private int currentRoundScore;
final int WINNING_SCORE = 100;
private boolean playerTurn;

public Pig()
{
System.out.println("Ready to play Pig?");
d1 = new GVdie(100);
d2 = new GVdie(100);
computerScore = 0;
playerScore = 0;
currentRoundScore = 0;
playerTurn = true;
}
//Returns currentRoundScore
public int getRoundScore()
{
return currentRoundScore;
}
//Returns playerScore
public int getPlayerScore ()
{
return playerScore;
}
//Returns computerScore
public int getComputerScore()
{
return computerScore;
}

public void rollDice()
{
d1.roll();
d2.roll();
System.out.println("die1: " + d1.getValue() + " die2: " + d2.getValue());
if (d1.getValue() == 1 || d2.getValue() == 1){
currentRoundScore = 0;  
}
else {
currentRoundScore += (d1.getValue() + d2.getValue());
}
System.out.println("Current Round Score: " + currentRoundScore);

}

public void playerRolls()
{
rollDice();
if (playerScore >= 100)
{
System.out.println("Player wins!");
}
else if (d1.getValue() == 1 && d2.getValue() == 1){
playerScore = 0;
currentRoundScore = 0;
playerTurn = false;
System.out.println("Terrible roll. Player Score set to 0");
}
else if (d1.getValue() == 1 || d2.getValue() == 1){
System.out.println("Bad roll - turns over. Player points: " + playerScore);
currentRoundScore = 0;
playerTurn = false;
}

}

public void playerHolds()
{
playerScore += currentRoundScore;
currentRoundScore = 0;
System.out.println("Player's current score: " + playerScore);
playerTurn = false;
}

public void computerTurn()
{
while (currentRoundScore < 19)
{
rollDice();
if (d1.getValue() == 1 && d2.getValue() == 1){
computerScore = 0;
currentRoundScore = 0;
playerTurn = true;
break;
}
else if (d1.getValue() == 1 || d2.getValue() == 1){
currentRoundScore = 0;
playerTurn = true;
break;
}
}
computerScore += currentRoundScore;
currentRoundScore = 0;
System.out.println("Computer's current score: " + computerScore);
}
// resets all the instance variables
public void restart ()
{
computerScore = 0;
playerScore = 0;
currentRoundScore = 0;
playerTurn = true;
}
//used by the GUI to return the die we instantiate in this class
public GVdie getDie(int num)
{
if (num == 1){
return d1;
}
else if (num == 2){
return d2;
}
else {
System.out.println("Not a legal value");
}
return getDie(num);
}
// if the playerScore surpases the WINNING_SCORE playerWon is true
public boolean playerWon(){
if (playerScore >= WINNING_SCORE){
return true;
}
else {
return false;
}
}
// if the computerScore surpases the WINNING_SCORE computerWon is true
public boolean computerWon(){
if (computerScore >= WINNING_SCORE){
return true;
}
else {
return false;
}
}
//the method we use to check whose turn it is
public boolean isPlayerTurn()
{
if (playerTurn == true){
return true;
}
else {
return false;
}
}
//part of our autoplay method, the player plays the same way as the computer
public void playerTurn ()
{
while (currentRoundScore < 19)
{
rollDice();
if (d1.getValue() == 1 && d2.getValue() == 1){
playerScore = 0;
currentRoundScore = 0;
playerTurn = false;
break;
}
else if (d1.getValue() == 1 || d2.getValue() == 1){
currentRoundScore = 0;
playerTurn = false;
break;
}
}
playerScore += currentRoundScore;
currentRoundScore = 0;
System.out.println("Player's current score: " + playerScore);
}
//player and computer (both playing by the same rules) whoever get's 100 first wins
public void autoGame ()
{
while ((playerScore < WINNING_SCORE) && (computerScore < WINNING_SCORE))
{
playerTurn();
computerTurn();
}
}

}

Explanation / Answer

public class Pig
{
public static void main(String args[]){
Pig game = new Pig();
}
private GVdie d1;
private GVdie d2;
private int computerScore;
private int playerScore;
private int currentRoundScore;
final int WINNING_SCORE = 100;
private boolean playerTurn;

public Pig()
{
System.out.println("Ready to play Pig?");
d1 = new GVdie(100);
d2 = new GVdie(100);
computerScore = 0;
playerScore = 0;
currentRoundScore = 0;
playerTurn = true;
}
//Returns currentRoundScore
public int getRoundScore()
{
return currentRoundScore;
}
//Returns playerScore
public int getPlayerScore ()
{
return playerScore;
}
//Returns computerScore
public int getComputerScore()
{
return computerScore;
}

public void rollDice()
{
d1.roll();
d2.roll();
System.out.println("die1: " + d1.getValue() + " die2: " + d2.getValue());
if (d1.getValue() == 1 || d2.getValue() == 1){
currentRoundScore = 0;  
}
else {
currentRoundScore += (d1.getValue() + d2.getValue());
}
System.out.println("Current Round Score: " + currentRoundScore);

}

public void playerRolls()
{
rollDice();
if (playerScore >= 100)
{
System.out.println("Player wins!");
}
else if (d1.getValue() == 1 && d2.getValue() == 1){
playerScore = 0;
currentRoundScore = 0;
playerTurn = false;
System.out.println("Terrible roll. Player Score set to 0");
}
else if (d1.getValue() == 1 || d2.getValue() == 1){
System.out.println("Bad roll - turns over. Player points: " + playerScore);
currentRoundScore = 0;
playerTurn = false;
}

}

public void playerHolds()
{
playerScore += currentRoundScore;
currentRoundScore = 0;
System.out.println("Player's current score: " + playerScore);
playerTurn = false;
}

public void computerTurn()
{
while (currentRoundScore < 19)
{
rollDice();
if (d1.getValue() == 1 && d2.getValue() == 1){
computerScore = 0;
currentRoundScore = 0;
playerTurn = true;
break;
}
else if (d1.getValue() == 1 || d2.getValue() == 1){
currentRoundScore = 0;
playerTurn = true;
break;
}
}
computerScore += currentRoundScore;
currentRoundScore = 0;
System.out.println("Computer's current score: " + computerScore);
}
// resets all the instance variables
public void restart ()
{
computerScore = 0;
playerScore = 0;
currentRoundScore = 0;
playerTurn = true;
}
//used by the GUI to return the die we instantiate in this class
public GVdie getDie(int num)
{
if (num == 1){
return d1;
}
else if (num == 2){
return d2;
}
else {
System.out.println("Not a legal value");
}
return getDie(num);
}
// if the playerScore surpases the WINNING_SCORE playerWon is true
public boolean playerWon(){
if (playerScore >= WINNING_SCORE){
return true;
}
else {
return false;
}
}
// if the computerScore surpases the WINNING_SCORE computerWon is true
public boolean computerWon(){
if (computerScore >= WINNING_SCORE){
return true;
}
else {
return false;
}
}
//the method we use to check whose turn it is
public boolean isPlayerTurn()
{
if (playerTurn == true){
return true;
}
else {
return false;
}
}
//part of our autoplay method, the player plays the same way as the computer
public void playerTurn ()
{
while (currentRoundScore < 19)
{
rollDice();
if (d1.getValue() == 1 && d2.getValue() == 1){
playerScore = 0;
currentRoundScore = 0;
playerTurn = false;
break;
}
else if (d1.getValue() == 1 || d2.getValue() == 1){
currentRoundScore = 0;
playerTurn = false;
break;
}
}
playerScore += currentRoundScore;
currentRoundScore = 0;
System.out.println("Player's current score: " + playerScore);
}
//player and computer (both playing by the same rules) whoever get's 100 first wins
public void autoGame ()
{
while ((playerScore < WINNING_SCORE) && (computerScore < WINNING_SCORE))
{
playerTurn();
computerTurn();
}
}

private static class GVdie {

public GVdie() {
}

private GVdie(int i) {
System.out.println("GVide"); //To change body of generated methods, choose Tools | Templates.
}

private int getValue() {
System.out.println("GVide");
return 1;//To change body of generated methods, choose Tools | Templates.
}

private void roll() {
System.out.println("GVide"); //To change body of generated methods, choose Tools | Templates.
}
}

}

Inside GVidie Methods you may add how you want to run the program.

Rest the program is running as programmed.

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