HELP NEEDED ASAP

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
 
P

Patricia Shanahan

rickysri wrote:
....
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???.....
....

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
 
O

Oliver Wong

First of all, read
http://riters.com/JINX/index.cgi/Suggestions_20for_20Asking_20Questions_20on_20Newsgroups#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
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 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[])
{
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))

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top