Ok, I have worked the program out a little bit more. But when I run it it is not printing out the users name.
My New Program is this:
import java.util.Scanner;
public class Assignment
{
String usersName="";
Boolean humanTurn = true;
Boolean computerTurn = true;
int dice;
int humanTurnPoints, computerTurnPoints;
int humanTotalPoints = 0;
int computerTotalPoints = 0;
private Scanner keyboard;
private Scanner key;
public void roll()
{
dice = (int)(Math.random()*6) + 1;
}
public int humanTurnScore()
{
{
humanTurnPoints = dice + humanTurnPoints;
System.out.println(usersName + "threw: " + dice);
System.out.println(usersName + "have scored: " + humanTurnPoints + " in your turn.");
} return humanTurnPoints;
}
public void humanTurnZero()
{
humanTurnPoints = 0;
}
public int computerTurnScore()
{
{
computerTurnPoints = dice + computerTurnPoints;
System.out.println("Computer has scored: " + computerTurnPoints + " in its turn.");
} return computerTurnPoints;
}
public void computerTurnZero()
{
computerTurnPoints = 0;
}
public Assignment(String usersName)
{
humanGame();
if(!humanTurn)
{
computerTurn();
}
}
public int humanGame()
{
System.out.println("To start the game please press 'r'.");
key = new Scanner(System.in);
String start = key.nextLine();
if(!start.equalsIgnoreCase("R"))
{
System.out.println("Make sure you are pressing 'r'.");
humanGame();
}
if(start.equalsIgnoreCase("R"))
{
System.out.println(usersName + "pressed + 'r'.");
System.out.println("Lets start.");
do{
roll();
if(dice == 1)
{
System.out.println(usersName + " got 1 and you lost your turn.");
System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
humanTurnZero();
computerTurn();
}
else if(dice != 1)
{
humanTotalPoints += dice;
if(humanTotalPoints >= 100)
{
System.out.println(usersName + " threw: " + dice);
System.out.println(usersName +" r GRAND TOTAL score is: " + humanTotalPoints);
System.out.println("Congratulations, you win!");
System.exit(0);
}
humanTurnScore();
System.out.println(usersName +" r GRAND TOTAL score is: " + humanTotalPoints);
System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
System.out.println(usersName + " can hold or roll again.");
System.out.println("To roll again press 'r' or 'h' to hold.");
keyboard = new Scanner(System.in);
String choice = keyboard.nextLine();
if (choice.equalsIgnoreCase("R"))
{
System.out.println(usersName + " pressed 'r'.");
System.out.println("Lets roll again.");
roll();
if(!choice.equalsIgnoreCase("R"))
{
System.out.println(usersName + " you didn't press 'r'. To make sure the program is running correctly please press 'r' to roll or 'h' to hold.");
humanGame();
}
}
if(choice.equalsIgnoreCase("h"))
{
System.out.println(usersName + " pressed 'h' and loose your turn.");
System.out.println(usersName + "'s Grand total is: " + humanTotalPoints);
humanTurnZero();
computerTurn();
}
}
}while(humanTurn);
}return dice;
}
public int computerTurn()
{
System.out.println("Now it's computer turn.");
do {
roll();
if(dice != 1)
{
computerTotalPoints += dice;
if(computerTotalPoints >=100)
{
System.out.println("Computer threw: " + dice);
System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
System.out.println("Game Over! the computer wins");
System.exit(0);
}
System.out.println("Computer threw: " + dice);
System.out.println("Computer's GRAND TOTAL score is: " + computerTotalPoints);
System.out.println(usersName + " Grand total is: " + humanTotalPoints);
computerTurnScore();
roll();
}
if(dice == 1)
{
System.out.println("Computer thrown 1 therefore it's your turn now.");
computerTurnZero();
humanGame();
}
if(computerTurnPoints >= 20)
{
System.out.println("Computer scored already " + computerTurnPoints + " you'd better start to focus.");
System.out.println("Please play again");
humanGame();
}
}while (computerTurn);
return dice;
}
public static void main(String[] args)
{
System.out.println("Please enter your name:");
Scanner vScanner = new Scanner(System.in);
String vUserName=vScanner.nextLine();
new Assignment(vUserName);
vScanner.close();
}
}
Please enter your name:
Diana
To start the game please press 'r'.
r
pressed + 'r'.
Lets start.
threw: 3
have scored: 3 in your turn.
r GRAND TOTAL score is: 3
Computer's GRAND TOTAL score is: 0
can hold or roll again.
To roll again press 'r' or 'h' to hold.
r
pressed 'r'.
Lets roll again.
threw: 2
have scored: 5 in your turn.
r GRAND TOTAL score is: 5
Computer's GRAND TOTAL score is: 0
can hold or roll again.
To roll again press 'r' or 'h' to hold.
r
This is what it is printing out. Not sure of what I did wrong.
--- Update ---
I actually got it to work. I saw where I needed to add two more lines. And now all I need to do is fix some spacing errors. Thank you for everyone's help. It is nice to be able to have a third eye in programming. I am still a beginner but I am determined to work this out. I am sure I will be back. Thanks again