Results 1 to 1 of 1
 02062008, 07:48 AM #1Member
 Join Date
 Feb 2008
 Posts
 1
 Rep Power
 0
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*n1));
for ( int i = 0; i <= (n1); )
i++;
boxCount++;
if ( k[n] == 0 )
aCount++;
k[n] = 1;
for ( int i = 0; i > (n1); )
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; 02062008 at 07:56 AM.
Similar Threads

Stuck on Two Questions, Please Help
By sylo18 in forum New To JavaReplies: 5Last Post: 03112008, 02:03 AM 
Just a Few Questions
By pringle in forum New To JavaReplies: 21Last Post: 01092008, 07:21 PM 
structuring the program
By ephem in forum New To JavaReplies: 1Last Post: 12242007, 09:53 PM 
questions
By Gilgamesh in forum New To JavaReplies: 3Last Post: 11282007, 12:18 AM 
3 Questions
By hiranya in forum AWT / SwingReplies: 4Last Post: 11142007, 05:57 AM
Bookmarks