newbie, please help with statistics of eight coin toss
I need help with the statistic of eight coin toss, with the number of coins tossed with the input of 'h' and the number of coin tossed with the input of 't'.
Here is what I have so far: with 2 errors, line 10 cannot find symbol,
public class CoinToss
{
BufferedReader in;
int headCount=0,tailCount=0;
public static void main(String[] args)
{
System.out.println("Start the input ");
Toss toss = new Toss();
try
{
toss.in = new BufferedReader(new InputStreamReader(System.in));
int count=0;
while(true)
{
String input =toss.in.readLine();
if(toss.validInput(input))
{
count++;
toss.updateCounter(input);
}
else
continue;
if(count==8)
break;
}
System.out.println("Head and Tail Count " + toss.headCount+""+toss.tailCount);
}catch(IOException e)
{e.printStackTrace();}
}
public boolean validInput(String input)
{
if(input.equals("h")|input.equals("H")|input.equals("t")|input.equals("T"))
return true;
else
return false;
}
public void updateCounter(String input)
{
if(input.equals("h")|input.equals("H"))
headCount++;
else
tailCount++;
}
}
[1329 byte] By [
bess12a] at [2007-10-3 7:01:20]

Toss toss = new Toss();should be:CoinToss toss = new CoinToss();
Thanks,now it says line 8, missing method body, or declare abstractpublic static void main(String[] args);Help please, it seems everytime I fixed one error it gives another....bess
> now it says line 8, missing method body, or declare> abstract> public static void main(String[] args);Remove the ; (semicolon) at the end of that method.
After I removed the semicolon, all wild broke loose...7 new errors..
line 10: cannot find symbol
location: class CoinToss
CoinToss = new CoinToss();
line 13: cannot find symbol
location: class CoinToss
toss.in = new BufferedReader(new InputStreamReader(System.in));
line 17: package toss does not exist
String input =toss.in.readLine();
line 18: cannot find symbol
symbol: variable toss
location: class CoinToss
if(toss.validInput(input))
line 21: cannot find symbol
symbol: variable toss
location: class CoinToss
toss.updateCounter(input);
line 28: cannot find symbol
symbol: variable toss
location: class CoinToss
System.out.println("Head and Tail Count " + toss.headCount+" "+toss.tailCount);
help please,
> After I removed the semicolon, all wild broke
> loose...7 new errors..
Those 7 errors are not new. They were there before, only the compiler didn't point them out earlier.
> line 10: cannot find symbol
> location: class CoinToss
> CoinToss = new CoinToss();
The first error. Look closely, what's wrong with it?
In some code posted earlier by you, you did something like this: Toss toss = new Toss();. Do you see the difference? (besides the class Toss and CoinToss difference)
I have been working my brain to no end, and I'm still stuck: 2 errors
Line 32: 'catch' without 'try'
{catch(IOException e)
Line 14: 'try' without 'catch' or 'finally'
try
import java.util.*;
import java.io.*;
public class CoinToss3
{
public static void main(String[] args) throws IOException{
BufferedReader in;
int headCount=0,tailCount=0;
System.out.println("Start the input ");
CoinToss toss = new Toss();
try
{
toss.in = new BufferedReader(new InputStreamReader(System.in));
int count=0;
while(true)
{
String input =toss.in.readLine();
if(toss.validInput(input))
{
count++;
toss.updateCounter(input);
}
else
continue;
if(count==8)
break;
{
System.out.println("Head and Tail Count " + toss.headCount+""+toss.tailCount);
{catch(IOException e)
{e.printStackTrace(); }
public boolean validInput(String input)
{
if(input.equals("h")|input.equals("H")|input.equals("t")|input.equals("T"))
return true;
else
return false;
}
public void updateCounter(String input)
{
if(input.equals("h")|input.equals("H"))
headCount++;
else
tailCount++;
{
}
}
}
}
}}
}
}
> I have been working my brain to no end, and I'm still
> stuck: 2 errors
If you'd manage to resolve those two errors, you'll face a lot more. You're doing so many things wrong. You are only guessing and typing stuff randomly. Needless to say: it won't work.
I could tell you what you were doing wrong, but it seems you don't have the basic knowledge of Java which is needed to understand those suggestions.
You should start with the first chapter of the textbook wich came with your Java course, or do some basic tutorials.
At least take the time to read (and study) this basic tutorial from Sun:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html
Good luck.
Wait I'm confused, the initial posting was 99% right except the line that said "Toss toss = new Toss();" instead of "CoinToss toss = new CoinToss();". All your curly braces and stuff have gotten mixed up since then. Can you just go back to the original?
p.s. Please highlight the code in your post and click the code button to make it pretty and readable
Message was edited by:
kindofblue
Thanks
For all the replies, especially the one about how I should go back to chapter 1 and reread the basic.....
I do believe I did that and that I still need help and that is why I was hoping this was the site to help out when one has a problem, and not made to feel even stupid...
Well, thanks anyway, I did get the problem fixed.
Bess
> I do believe I did that and that I still need help
> and that is why I was hoping this was the site to
> help out when one has a problem, and not made to feel
> even stupid...
>
I have just read through this thread and I don't see where anyone tried to make you feel stupid.
> I have just read through this thread and I don't see
> where anyone tried to make you feel stupid.
I agree with you sabre. I think the problem stems from the procedural approach vs a OO approach. I could see 2 classes, a Coin class that is responsible for just determining the result of a filp, and a driver class that would 'flip' many coins and tabulate the results.
What do you think? This is a Algorithms forum isnt it? Maybe this thread should be moved to a Design forum first, then let the OP worry about implementation.
JMO
JJ
> What do you think? This is a Algorithms forum isnt it? Maybe this
> thread should be moved to a Design forum first, then let the OP
> worry about implementation.
Definitely not. If anything this thread should be moved to "New to programming" forum. Design and Algorithms forums are not meant to answer compile errors (*yawn*). The OP can't handle the advice / is too lazy to read chapters on compile errors or basic language structure. The OPs attitude is just another flavour of the typical response from someone who is too lazy to do the work.