Hello, I am a college student looking for help on a CSC project, "The Pig Game". I was wondering if someone would go over my code and help me with what I am doing wrong.
(*Note I am using netbeans as my compiler. I also am loading an attachment which is a picture of the UML I am suppose to use.)
Here is my code.
Code:
public class Course_Project2 {
public static void main(String[] args)
{
PigGame project = new PigGame();
project.play();
}
}
public class Die
{
private final int MAX = 6; // maximum face value
private int faceValue; // current value showing on the die
//-----------------------------------------------------------------
// Constructor: Sets the initial face value.
//-----------------------------------------------------------------
public Die()
{
faceValue = 1;
}
//-----------------------------------------------------------------
// Rolls the die and returns the result.
//-----------------------------------------------------------------
public int roll()
{
faceValue = (int)(Math.random() * MAX) + 1;
return faceValue;
}
//-----------------------------------------------------------------
// Face value mutator.
//-----------------------------------------------------------------
public void setFaceValue (int value)
{
faceValue = value;
}
//-----------------------------------------------------------------
// Face value accessor.
//-----------------------------------------------------------------
public int getFaceValue()
{
return faceValue;
}
//-----------------------------------------------------------------
// Returns a string representation of this die.
//-----------------------------------------------------------------
public String toString()
{
String result = Integer.toString(faceValue);
return result;
}
}
public class PairOfDice
{
// instance data
private Die die1;
private Die die2;
//------------------------------------------
// Constructor: Intializes two dice.
//------------------------------------------
public void PairOfDice()
{
die1 = new Die();
die2 = new Die();
}
//----------------------------------------------------------
// Rolls the pair by rolling each die. The sum is returned.
//----------------------------------------------------------
public int roll()
{
return die1.roll() + die2.roll();
}
//------------------------------------------------------
// Returns a string representation of the pair of dice.
//------------------------------------------------------
@Override
public String toString()
{
return "[ " + die1.getFaceValue() + " : " + die2.getFaceValue() + " ]";
}
public void setDie1(int val)
{
die1.setFaceValue(val);
}
public void setDie2(int val)
{
die2.setFaceValue(val);
}
public int getDie1()
{
return die1.getFaceValue();
}
public int getDie2()
{
return die2.getFaceValue();
}
}
import java.lang.String;
public abstract class Player
{
private int roundPts;
private int gamePts;
private String name;
public Player(String n)
{
}
public void takeTurn(PigDice p)
{
}
@Override
public String toString()
{
return ("Points earned this round " + roundPts) +
("Total is" + (roundPts + gamePts));
}
public void setGamePts(int Val)
{
gamePts += Val;
}
public void setRoundPts(int Val)
{
roundPts += Val;
}
public int getGamePts()
{
return gamePts;
}
public int getRoundPts()
{
return roundPts;
}
public abstract boolean beAPig();
}
public class Computer extends Player
{
public Computer(String n)
{
if(Player.getRoundPts() < 20)
else
Player.takeTurn();
}
}
import java.util.Scanner;
public class Human extends Player
{
public Human(String n)
{
Scanner Scan = new Scanner(System.in);
System.out.println("Would you like to roll again [y/n]? ");
String response = Scan.nextLine();
if (response.equals("y"))
else
}
}
import java.util.Scanner;
public class PigGame
{
private Player player1, player2;
private PigDice dice;
public PigGame(Player Human, Player Computer, PigDice pigDice)
{
System.out.println( "Welcome to the Pig Game");
PigDice dice = new PigDice();
player1 = new Human("Player 1");
player2 = new Computer("Computer AI");
}
public void play()
{
Scanner Scan = new Scanner(System.in);
CurPlayer = new
}
public String toString()
{
}
}
public class PigDice
{
public PigDice()
{
super();
}
public int roll()
{
int result = super.roll();
if(die1.getFaceValue()==1||die2.getFaceValue()==1)
{
result = 3;
}
if(die1.getFaceValue()==1&&die2.getFaceValue()==1)
{
result = 2;
}
return result;
}
