R
rickysri
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
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