Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-06-2008, 08:48 AM
Member
 
Join Date: Feb 2008
Posts: 1
sdkevinb is on a distinguished road
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 08:56 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stuck on Two Questions, Please Help sylo18 New To Java 5 03-11-2008 03:03 AM
Just a Few Questions pringle New To Java 21 01-09-2008 08:21 PM
structuring the program ephem New To Java 1 12-24-2007 10:53 PM
questions Gilgamesh New To Java 3 11-28-2007 01:18 AM
3 Questions hiranya AWT / Swing 4 11-14-2007 06:57 AM


All times are GMT +3. The time now is 02:20 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org