it's my homework and i have no clue what i'm doing. i pay attention in class but i still don't know what's going on! it's a 2 part project, with a cointoss class and histogram class.

this is my cointoss class

import java.util.Scanner;

public class CoinToss {

  private static final int MIN_HEADS = 0;   // minimum number of heads per set

  /**
   * main method:
   * ask the user how many sets of coin flips and how many flips per set
   * count occurances of heads in user specified number of sets of coin flips
   * draw a horizontal and vertical histogram of the number of heads
   */
  public static void main(String[] args) {

    // set up to get user input
    Scanner scan = new Scanner(System.in);
   
    // ask user for the number of sets of coin flips
    System.out.println("How many sets of coin flips do you want?");
    int nSets = scan.nextInt();
    
    // ask user for the number of coin flips per set 
    System.out.println("How many coin flips per set do you want?");
    int nFlips = scan.nextInt();

    // maximum number of heads that can occur is number of flips
    int maxHeads = nFlips;      

    // calculate maximum length of histogram bars based on number of flips per set
    // based on finding the number of combinations for half heads / half tails
    //                n!
    // formula is -----------  with r = n/2
    //             r! (n-r)!
    
    int maxLength = factorial (nFlips) / 
                    (factorial (nFlips / 2) * factorial (nFlips - nFlips / 2));
    
    // instantiate a coin object named myCoin
    Coin myCoin = new Coin();
      
    // step 1:
    // declare an int array named "counts" to count coin flip occurences
    // make its size one larger than maxHeads
   int counts[] = new int [maxHeads + 1];
    


    // step 2:
    // initialize all of the values in the array to 0
    for(nFlips=1;nFlips<=maxHeads;nFlips++);
    counts[nFlips] = 0;
    
    

    // step 3:
    // flip the coin for n sets with nFlips flips per set
    // count the number of heads in each set (heads = 1, tails = 0)
    for (int i = 0; i < nSets; i++)
    {
      int sum = 0;
      for (int j = 0; i <nFlips; j++)
      {
        sum = sum +(myCoin.flip()? 1:0);
      }
    }
 
      
    

    // step 4:
    // print out the estimated probabilities of all heads and all tails
    System.out.println((float) counts [MIN_HEADS] / nSets);
  

    
    // step 5:
    // instantiate an object of the Histogram class with 
    // the array to be drawn, the indices of valid data,
    // and the maximum length of the bars in the histogram
    //
    // call its two draw methods to draw the two histograms
    int maxCount = 0;
    for (int i = MIN_HEADS; i < maxHeads +1; i++)
    {
      if(maxCount <= counts [i])
      {
        maxCount = counts [i];
      }
      break;
    }
  }
      
  // function to calculate factorial of n
    public static int factorial(int n)
    {
    int factorial = 1;
    
   
    // write the code for a loop to calculate factorial of n here
    
    while(n!=1);
    {
      factorial=n*(factorial);
      n--;
    }
  
    return factorial;
    }}
 /*201020*/

and this is my histogram class

public class Histogram 
{
  private int [] values;
  private int minIndex;
  private int maxIndex;
  private int maxLength;
  
  /** constructor for histogram drawing class
    * @param values the array of integer values to draw
    * @param minIndex the lowest index in the array for the range to draw
    * @param maxIndex the highest index in the array for the range to draw
    * @param maxLength the length of line to draw for the largest value
    */
  
  public Histogram(int [] values, int minIndex, int maxIndex, int maxLength) 
  {
    // initialize the values of the instance variables from the constructor parameters
    this.values = new int [maxIndex + 1];   // allocate memory for a copy of the values array
    this.minIndex = minIndex;
    this.maxIndex = maxIndex;
    this.maxLength = maxLength;

    // step 6: 
    // find largest number in values array for scaling length of bars
    int MaxValue = values[0];
    for(int i=minIndex; i<=maxIndex; i++)
    {
      if (values[i] > MaxValue)
        MaxValue = values[i];
    }
    
  
    // step 7:
    // copy data from values array to this.values array while scaling to maximum length of bars
    System.arraycopy(values,0,this.values,0,values.length);
    
    
    }
  
  /** draw a horizontal bar graph
    */
  
  public void drawHor()
  {
    // step 8:
    // draw horizontal bar graph (one line per roll value)
    for (int i = 1; i<values.length; i++)
      System.out.print("Value " + i + ":" + "\t" + values[i]);
      System.out.println("*");
    }
  
  
  /** draw a vertical bar graph
    */
  
  public void drawVer()
  {

    // step 9:
    // draw vertical bar graph (one column per roll value)
    for (int i = 1; i<values.length; i++)
      System.out.print("Value " + i + ":" + "\t" + values[i]);
      System.out.println("*");
    
    
    
  }
}/*201020*/

any help would be greatly appreciated! i have no clue what im doing!

Are you going to ask an actual question or just hope someone wants to read all your code and try to figure out what it does and does not do?

Member Avatar for hfx642

What Ezzaral said!!

You have a method called factorial AND an int called factorial.
YOU SHOULD NOT DO THAT!!!
Also, in your method, you are not calling your method (recursion) because you are not passing any parameters.
Thus, your method is NOT recursive (which IS what you intended).

Are you going to ask an actual question or just hope someone wants to read all your code and try to figure out what it does and does not do?

sorry! when i run the program, itll ask me to input how many sets and how many flips per set, but then itll just keep loading and nothing happens.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.