I am currently working on a homework assignment and would like some guidance as to where to solve a part of a problem. I'm not looking for answers, just suggestions/guidance as to where to start from where I currently am in the program to solve what I need to do. I am making a game of craps(I have already solved the majority of the problem), and I need to have the output print 10 stars for every game they win, then print the total games won out of how many games played at the end. This is what the output should look like....
You win
**********
Game 2, press enter to roll
You rolled 1 1
You lose
**********
Game 3, press enter to roll
You rolled 5 6
You win
********************
You won 2 game(s) out of 3
This is my code so far....which essentially just plays the game of craps without the output required above.
import java.util.*;
import java.math.*;
public class GameOfCraps {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of games: ");
int numGames = input.nextInt();
while(numGames <= 0){
System.out.print("Number must be > 0, please enter again: ");
numGames = input.nextInt();
}
GameNumber(numGames);
}
// Method to run actual game of craps
public static void CrapsGame(){
int roll1, roll2, total;
Random random = new Random();
Scanner input = new Scanner(System.in);
System.out.print("press enter to roll");
input.nextLine();
roll1 = 1 + random.nextInt(6);
roll2 = 1 + random.nextInt(6);
total = roll1 + roll2;
if(total == 7 || total == 11){
System.out.println("You rolled " + roll1 + " " + roll2 + "\nYou win");
}
else if(total == 2 || total == 3 || total == 12){
System.out.println("You rolled " + roll1 + " " + roll2 + "\nYou lose");
}
else if(total == 4 || total == 5 || total == 6 || total == 8 || total == 9 || total == 10){
System.out.println("You rolled " + roll1 + " " + roll2);
System.out.print("Point is " + total + " press enter to roll");
input.nextLine();
roll1 = 1 + random.nextInt(6);
roll2 = 1 + random.nextInt(6);
total = roll1 + roll2;
if(total == 7){
System.out.println("You rolled " + roll1 + " " + roll2 + "\nYou lose");
}
else{
System.out.println("You rolled " + roll1 + " " + roll2 + "\nYou win");
}
}
}
// Method to generate number of games to play based on input
public static void GameNumber(int num){
for(int i = 1; i <= num; i++){
System.out.print("Game " + i +", ");
CrapsGame();
}
}
}
I'm not really sure where to approach this part of the program, I know I need maybe a counter variable with a loop to figure out how many games they have won so far...but I guess I'm just kind of lost as to which method to put it in...or if I should create a new method entirely....any suggestions would be appreciated thanks!