I have the code done for the rest of my program but I can not get the asterisks in my histogram to print can you help??
Thanks In Advance!!
Here is a copy of my code (driver and class).
public class diceSimulation
{
public static void main(String[] args)
{
char choice; //user's choice of what he/shewants to do
boolean done = false; //flag that tells whether user wants to quit
diceSimulation2 diceSimulation = new diceSimulation2();
System.out.println("Welcome to my dice throwing simulation");
do
{
System.out.println("Options: (n)ew simulation, (a)dditional rolls," +
" (p)rint report, (q)uit");
System.out.print("Enter n, a, p, or q ==> ");
choice = Input.readChar();
switch (choice)
{
case 'n': case 'N':
diceSimulation.newSimulation();
break;
case 'a' : case 'A':
diceSimulation.additionalRolls();
break;
case 'p': case 'P':
diceSimulation.printReport();
break;
case 'q': case 'Q':
done = true;
break;
default:
System.out.println("Invalid selection.");
}// end switch
}while (!done);
}
}// end main
This is the Class
public class diceSimulation2
{
final int numofRolls = 13;
int rolls;
int [] frequency = new int [numofRolls + 1];
//New Simulation
public void newSimulation()
{
int n = 12;
for (int i=2; i<n; i++)
{
frequency[i] = 0;
}
System.out.print("How many dice rolls would you like to simulate?");
rolls = Input.readInt();
}
/************************************************************************************************/
//Roll the dice additional times
public void additionalRolls()
{
int aRolls;
System.out.print("How many additional dice rolls would you like to simulate?");
aRolls = Input.readInt();
rolls += aRolls;
results(aRolls);
}
/*************************************************************************************************/
//Get Results
public void results(int totalRolls)
{
int sum;
int i;
for(i=0; i<totalRolls; i++)
{
sum = (int) (Math.random()*6) +1
+ (int) (Math.random()*6) +1;
frequency[sum]++;
}
}
/************************************************************************************************/
//Print Histogram
public void printReport()
{
String rollSpace = " ";
float tRolls;
int numofAsterisks;
double onePercent = rolls / 100 ;
int sum;
int i;
System.out.println("DICE ROLLING SIMULATION RESULTS");
System.out.println("Each '*' represents 1% of the total number of dice rolls.");
System.out.println("Total number of dice rolls = " +rolls);
for(sum=2; sum<=12; sum++)
{
rollSpace = "";
//tRolls = (float) frequency[sum]/rolls;
//numofAsterisks = Math.round(tRolls * 100);
numofAsterisks = (int) (frequency[sum] / onePercent);
System.out.println(sum + ": ");
//if(sum<10)
//{
//rollSpace += "";
//}
//rollSpace += sum+":";
for(i=0; i<numofAsterisks ; i++)
{
//rollSpace += "*";
System.out.print("*");
}
}
}
}