My program complies and runs, but the random method is selecting randoms numbers instead of the numbers I assigned the colours? Any hints on hoe I can fix this??
import java.util.*; import java.util.Random; public class AssigOne112 { public static void main(String[] args) { // Initialising Scanner and setting Random Scanner sc= new Scanner(System.in); Random generator; // Set seed value final int SEED = 400; // Colour variable for vehicles final int BLACK = 0; final int BLUE = 1; final int CYAN = 2; final int DARK_GREY = 3; final int GREY = 4; final int GREEN = 5; final int LIGHT_GREY = 6; final int MAGENTA = 7; final int ORANGE = 8; final int PINK = 9; final int RED = 10; final int WHITE = 11; final int YELLOW = 12; // Value of coloured cars final int BLACK_CAR_VALUE = 1; final int WHITE_CAR_VALUE = 1; final int GREEN_CAR_VALUE = 2; final int YELLOW_CAR_VALUE = 3; final int BLUE_CAR_VALUE = 4; final int ORANGE_CAR_VALUE = 5; final int CYAN_CAR_VALUE = 0; final int DARK_GREY_CAR_VALUE = 0; final int GREY_CAR_VALUE = 0; final int LIGHT_GREY_CAR_VALUE = 0; final int MAGENTA_CAR_VALUE = 0; final int PINK_CAR_VALUE = 0; //Calculated players average double avgScore1; double avgScore2; // Variables // Players name input String name1; String name2; String playerOne; String playerTwo; String name; // Players sequence boolean playerSequence; int currentPlayer; // Variables for players scoring int player1Total = 0; int player2Total = 0; int scoreInning = 0; // Final score int score =0; // Assigns winner int won = 0; // Assigns number of innings int playGame = 0; // Starts count for innings int innings = 0; int colourNum = 0; String colour; // Numbers 1-9 are cars, number 0 is other vehicle int vehicleType = 0; boolean isCar = (vehicleType !=0); //Game Rules System.out.println("Car Cricket Game"); System.out.println("================"); System.out.println("Scoring: non white/black/red/green/yellow/blue/orange car: 0 runs."); System.out.println("White/black car: 1 run."); System.out.println("Non-red van/truck/bus/SUV: 1 run."); System.out.println("Green car: 2 runs."); System.out.println("Yellow car: 3 runs."); System.out.println("Blue car: 4 runs."); System.out.println("Orange car: 5 runs."); System.out.println("Red van/truck/bus/SUV: 6 runs."); System.out.println("Red car: OUT!"); System.out.println(); System.out.println("Time to play!"); System.out.println(); //Ask user to input names and innings wanting to play. System.out.print("Two players are required to play this game. Please enter the name of one of the players: "); playerOne = sc.next(); System.out.print("Please enter the name of the other player: "); playerTwo = sc.next(); System.out.print("Answering either true or false, is " + playerOne + " going to bat first? "); playerSequence = sc.nextBoolean(); System.out.print("How many innings do you want to play in this game? "); playGame = sc.nextInt(); //installation of Random function generator = new Random(SEED); // For loop to count innings for(innings=1; innings<=playGame; innings ++) { System.out.println("Innings # " + innings); // For loop to alternate between players for(currentPlayer = 1; currentPlayer <=2; currentPlayer ++) { if(playerSequence) { name1 = playerOne; name2 = playerTwo; } else { name1 = playerTwo; name2 = playerOne; } System.out.print("Player #" + currentPlayer + " "); // determine current player's name if (currentPlayer == 1) { name = name1; } else { name = name2; } System.out.println("(" + name + ")"); // add score to a global scoring of given player if (currentPlayer == 1) { player1Total = player1Total + score; } else { player2Total = player2Total + score; } // While loop continues until red colur is choosen while(colourNum!=RED) { colourNum = generator.nextInt(13); vehicleType = generator.nextInt(10); score = colourNum; colour = ""; if (vehicleType >= 1 && vehicleType <= 9) { isCar = true; // add score by given colour to inning's score scoreInning += score; switch (colourNum) { case BLACK: colour = "Black"; score = score + BLACK_CAR_VALUE; break; case BLUE: colour = "Blue"; score = score + BLUE_CAR_VALUE; break; case CYAN: colour = "Cyan"; score = score + CYAN_CAR_VALUE; break; case DARK_GREY: colour = "Dark Grey"; score = score + DARK_GREY_CAR_VALUE; break; case GREY: colour = "Grey"; score = score + GREY_CAR_VALUE; break; case GREEN: colour = "Green"; score = score + GREEN_CAR_VALUE; break; case LIGHT_GREY: colour = "Light Grey"; score = score + LIGHT_GREY_CAR_VALUE; break; case MAGENTA: colour = "Magenta"; score = score + MAGENTA_CAR_VALUE; break; case ORANGE: colour = "Orange"; score = score + ORANGE_CAR_VALUE; break; case PINK: colour = "Pink"; score = score + PINK_CAR_VALUE; break; case RED: colour = "Red"; //score = score + RED_CAR_VALUE; break; case WHITE: colour = "White"; score = score + WHITE_CAR_VALUE; break; case YELLOW: colour = "Yellow"; score = score + YELLOW_CAR_VALUE; break; } System.out.println(colour + " car..." + score); } if(vehicleType==0) { isCar = false; System.out.println(colour + " van/truck/bus/SUV..." + score); } } // If loop for random red colour selection if(colourNum == RED) { isCar=true; System.out.println("OUT!"); System.out.println("Total was " + scoreInning); System.out.println("Current scores: "); System.out.println(name1 + ": " + player1Total); System.out.println(name2 + ": " + player2Total); } if(isCar = false) { colourNum = RED; scoreInning += 6; if (currentPlayer == 1) { player1Total = sc.nextInt(); player1Total += 6; } else { player2Total = sc.nextInt(); player2Total += 6; } System.out.println("6"); } else { scoreInning += 1; if (currentPlayer == 1) { player1Total += 1; } else { player2Total += 1; } System.out.println("1"); } //Find the winner. if (player1Total == player2Total) { System.out.println("Draw!"); } else if (player1Total > player2Total) { avgScore1 = player1Total/playGame; System.out.println(name1 + " (with avg " + avgScore1 + ") won"); } else if (player1Total < player2Total) { avgScore2 = player2Total/playGame; System.out.println(name2 + " (with avg " + avgScore2 + ") won"); } } } } }