Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

HELP NEEDED ASAP

Thread view: 
rickysri - 19 May 2006 22:45 GMT
Hi

I have created a Trial functional class (a probability problem) for a
single coin toss of a fair coin that results in heads or tails...over the
long run probability theory says that occurecne of either outcome
approaches 0.5....
The Trial object created is functional class encapsulates n number of
tosses in trial array of type char that will hold outcomes of each
indvdidual toss in trial,count of no of heads occuring during trial and
count of no of tails... Size of array( no of tosses per trial) is
determined when array is instantiated...

It is the test class I am having problems in accepting two command line
arguments entered as integers the condition are such that the first is the
number of trials must be greater than zero second number of tosses greater
than zero and less than constant 9999999. For each trial i need to display
the number of trial upto and including the number of trials,instantiate a
trial object(simulate the tossing of the coin the no of times per
trial)and determine and display the longest run in the trial...How to
determine the longest run in the trial???.....

Functional class

import java.lang.*;
public class Trial
{
int n; //attribute: n of Integer type-no of tosses in a trial
char[] outcome; //attribute: outcomes of char array type
int counth;
int countt;

public void Trial(int value)
{
n=value;
outcome=new char[n];
}

public int getN()
{
return n; // n stands for the number of tosses in a trial
}
public char getOutcome()
{
return outcome;
}
private char random()
{
for (int index=0;index<=n;index++)
{
if ((0 + (Math.random()*1.0)<0.5))
{
outcome[n]='t';
counth++;
}
else if ((0 + (Math.random()*1.0)>=0.5))
{
outcome[n]='h';
countt++;
}
}
return outcome[n];
}
}
public class Experimenter
{
public static void main(String args[])
{
String s0=args[0];
String s1=args[1];
int NumTrials=Integer.parseInt(s0);
int NumTosses=Integer.parseInt(s1);

if (NumTrials>0 && (NumTosses>0 && NumTosses<9999999))
{
System.out.print("Number of Trials = "+NumTrials);
System.out.print("\nNumber of Tosses per Trial = "+NumTosses);
}
else if (NumTrials !=0 && NumTosses>9999999)
{
System.out.print("\n?? Experiment numTrials numTosses");
System.exit(0); //exits the application
}
else if (NumTrials>0 && (NumTosses>0 && NumTosses<9999999))
{
for (i=0;i<=NumTrials;i++)
{
??? //initialize percentage difference accumulator

}
}

Any help will be appreciated

Thanks
Patricia Shanahan - 19 May 2006 23:04 GMT
...
> It is the test class I am having problems in accepting two command line
> arguments entered as integers the condition are such that the first is the
[quoted text clipped - 4 lines]
> trial)and determine and display the longest run in the trial...How to
> determine the longest run in the trial???.....
...

There seem to be several parts to your question, and I'm not sure what
it is that is giving you trouble.

Have you worked out how to read numeric arguments from the command
line? If not, I suggest doing that in a separate program that just
reports the arguments.

Do you know exactly what you are meant to be doing? If not, I suggest
experimenting with pencil, paper, and a coin, using small numbers of
tosses and trials.

Patricia
Oliver Wong - 19 May 2006 23:09 GMT
First of all, read
http://riters.com/JINX/index.cgi/Suggestions_20for_20Asking_20Questions_20on_20N
ewsgroups#Urgent


> I have created a Trial functional class (a probability problem) for a
> single coin toss of a fair coin that results in heads or tails...over the
[quoted text clipped - 5 lines]
> count of no of tails... Size of array( no of tosses per trial) is
> determined when array is instantiated...

   It sounds like you didn't bother to actually type in this post, but just
copy and pasted from the assignment question.

> It is the test class I am having problems in accepting two command line
> arguments entered as integers the condition are such that the first is the
> number of trials must be greater than zero second number of tosses greater
> than zero and less than constant 9999999.

   This sentence is difficult to understand. Perhaps some punctuation is
missing?

   Anyway, I looked at your code, and you've got this part right.

[most of the code snipped]
> public static void main(String args[])
> {
[quoted text clipped - 4 lines]
>
> if (NumTrials>0 && (NumTosses>0 && NumTosses<9999999))

   The actual logic of your program is probably incorrect though. You'll
have to actually reason about what your if statements are checking against,
and what to do in each situation. Try writing your program in pseudocode
first. If you get stuck, post the pseudocode you wrote and we'll help you
from there.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.