Results 1 to 1 of 1
  1. #1
    sdkevinb is offline Member
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0

    Default a few questions on structuring my program...

    **I know I didn't format my code properly. I am doing a bunch of homework at the moment and am rather busy. Could you also tell me the tag to format it like I am supposed to?**

    Hey guys, I am brand new to this forum and I hope I will get some good feedback! Anyways, I am working on a program right now that I am somewhat stuck on. It generates a random number between 0 and n that the user inputs, then sorts it into either set A or set B. Imagine a collector who is trying to complete either series A or series B. "n" is the size of the series. Say the series is made up of tokens, that are unique to boxes of cereal. What my program does it trys to figure out how many boxes of cereal you need to open in order to complete the series. If my explanation is too vague...just check out my code. The relevant statistic is the # of boxes needed to open before either A or B is complete. I also need to find the max, min, and std dev of the number of boxes. This is what I have so far, but I'm not completely done yet. I was wondering what I am missing? I am stumped as to how to keep going at this point. Any help is appreciated!!

    //The Crackerjack Collector
    //A loop that counts how many boxes a girl must open in order to complete either series A or B

    import java.io.*;
    class pa1 {

    static BufferedReader keybd =
    new BufferedReader (new InputStreamReader (System.in));

    static int numberOfExperiments = 0;
    static int aCount = 0;
    static int bCount = 0;
    static int boxCount = 0;
    static int totalBoxCount = 0;

    static boolean say_yes (String question) throws IOException {
    System.out.print (question);
    char answer = (keybd.readLine()).charAt(0);
    return (answer == 'Y' || answer == 'y');
    }

    static void hello () throws IOException {
    System.out.println("Welcome to the program.");
    }

    static void goodbye () throws IOException {
    System.out.println("Goodbye!");
    }

    static void do_experiment () throws IOException {
    System.out.print("Enter n: ");
    int n = new Integer(keybd.readLine()).intValue();
    System.out.print("How many times shall we run? ");
    int r = new Integer(keybd.readLine()).intValue();

    int [] x = new int[n];
    int [] k = new int[0]; // Don't know about this part!!
    int [] w = new int[0];

    for ( int i = 0; i < n; i++ )
    x[i] = (int)(Math.random() * (2*n-1));


    for ( int i = 0; i <= (n-1); )
    i++;
    boxCount++;

    if ( k[n] == 0 )
    aCount++;
    k[n] = 1;


    for ( int i = 0; i > (n-1); )
    i++;
    boxCount++;

    if ( w[n] == 0 )
    bCount++;
    w[n] = 1;

    numberOfExperiments++;

    if ( aCount == n)
    System.out.print("You opened " + boxCount);
    System.out.println(" boxes and completed series A!");
    totalBoxCount = totalBoxCount + boxCount;

    if ( bCount == n)
    System.out.print("You opened " + boxCount);
    System.out.println(" boxes and completed series B!");
    totalBoxCount = totalBoxCount + boxCount;

    numberOfExperiments++;

    if ( numberOfExperiments == r)
    System.out.print("The experiment has now run" + r);
    System.out.println(" times. Here are the results: ");

    // STATISTICS

    System.out.println("Minimum number of boxes to complete a series: ");
    System.out.println("Maximum number of boxes to complete a series: ");
    System.out.println("Average number of boxes to complete a series: ");
    System.out.println("Standard Deviation: ");
    }

    public static void main (String[] args) throws IOException {
    hello();
    while ( say_yes("Do an experiement? Y/N: " ) )
    do_experiment();
    goodbye();
    }
    }
    Last edited by sdkevinb; 02-06-2008 at 07:56 AM.

Similar Threads

  1. Stuck on Two Questions, Please Help
    By sylo18 in forum New To Java
    Replies: 5
    Last Post: 03-11-2008, 02:03 AM
  2. Just a Few Questions
    By pringle in forum New To Java
    Replies: 21
    Last Post: 01-09-2008, 07:21 PM
  3. structuring the program
    By ephem in forum New To Java
    Replies: 1
    Last Post: 12-24-2007, 09:53 PM
  4. questions
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 11-28-2007, 12:18 AM
  5. 3 Questions
    By hiranya in forum AWT / Swing
    Replies: 4
    Last Post: 11-14-2007, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •