Under the addRolls method I need to populate the nums array with the frequency of the 'total' variable numbers. These method adds the two dice rolls together properly and stores it in the 'total' variable but I cannot seem to properly throw them into an array that does the frequency such as the method above it - indFreq. In case that's hard to follow I think this might make more sense : It's just the addRolls method that needs to be looked at I believe. It needs to return an array with the frequency of the 'total' numbers.
import java.util.Scanner;
public class Project2 {
public static void main( String[] args )
{
Scanner inp = new Scanner( System.in );
int matrix [][]=new int[100][2];
System.out.print("Press 'q' to exit or 'enter' to continue: \t");
String response =inp.nextLine();
while ( !response.toLowerCase().equals("q") ){
for (int row=0;row<matrix.length;row++){
for (int column=0;column<matrix[row].length;column++)
matrix[row][column]=diceRoll();
}
int [] hist1=indFreq(matrix);
int [] roll=addRolls(matrix);
for (int i=1;i<hist1.length;i++){
String star=starPrint(hist1[i]);
System.out.print(" \n" +hist1[i]+ star);
}
System.out.println("");
// }
System.out.print("\n\nPress 'q' to exit or 'enter' to run again:\t");
response =inp.nextLine();
}
}
public static int diceRoll(){
int num=(int)(Math.random()*6+1);
return num;
}
public static String starPrint(int value){
String star= "";
for (int i=0;i<value;i++){
star +="*";
}
return star;
}
public static int [] indFreq(int [][] matrix){
int [] nums =new int[7];
for (int i=0;i<matrix.length;i++){
for (int j=0; j<matrix[i].length;j++)
nums[matrix[i][j]] += 1;
}
return nums;
}
public static int [] addRolls(int [][] matrix){
int total= 0;
int[]nums=new int[13];
//Adds the rows together.
for (int i=0;i<matrix.length;i++){
total=0;
for (int j=0;j<matrix[i].length;j++)
total+=matrix[i][j];
}
return nums;
}
}