• Create Account

### #Actualm3mb3rsh1p

Posted 12 October 2012 - 06:33 PM

Hi. I'm also a beginner so I thought I'd share my solution. I'm stuck at how to count the flips without loops because I don't quite yet have a firm grasp of the Java utils.

I enjoyed this. Thanks to all!
import java.util.Random;
import java.util.Arrays;
import java.util.Collections;

public class Coin
{
public enum Side { heads, tails, edge };

public Coin()
{
_side = Side.edge;
}
public Coin(Side side)
{
_side = side;
}
public Coin(Random generator)
{
flip(generator);
}
public void flip(Random generator)
{
double value = generator.nextDouble();

if(value < 0.5 )
else if(value > 0.5)
{_side = Side.tails;}
else
{_side = Side.edge;}
}
public boolean equals(Coin other)
{
return _side == other._side;
}
public String toString()
{
return _side.toString();
}
private Side _side;

public static void main(String[] args)
{
Coin tails = new Coin(Side.tails);

Random rand = new Random();

Coin[] coins = new Coin[]
{
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand)
};

System.out.println(Arrays.toString(coins));

int numTails = Collections.frequency(Arrays.asList(coins), tails);
System.out.println("There are " + numTails + " tails.");
}
}


I encountered some challenges while finding the "right way"
- no easy way to "apply"
- countif/equality not working here
- *()&(SFHKJHSF(&(*&:>( code tags!!

### #10m3mb3rsh1p

Posted 12 October 2012 - 06:00 PM

Hi. I'm also a beginner so I thought I'd share my solution. I'm stuck at how to count the flips without loops because I don't quite yet have a firm grasp of the Java utils.

I enjoyed this. Thanks to all
import java.util.Random;
import java.util.Arrays;
import java.util.Collections;

public class Coin
{
public enum Side { heads, tails, edge };

public Coin()
{
_side = Side.edge;
}
public Coin(Side side)
{
_side = side;
}
public Coin(Random generator)
{
flip(generator);
}
public void flip(Random generator)
{
double value = generator.nextDouble();

if(value < 0.5 )
else if(value > 0.5)
{_side = Side.tails;}
else
{_side = Side.edge;}
}
public boolean equals(Coin other)
{
return _side == other._side;
}
public String toString()
{
return _side.toString();
}
private Side _side;

public static void main(String[] args)
{
Coin tails = new Coin(Side.tails);

Random rand = new Random();

Coin[] coins = new Coin[]
{
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand)
};

System.out.println(Arrays.toString(coins));

int numTails = Collections.frequency(Arrays.asList(coins), tails);
System.out.println("There are " + numTails + " tails.");
}
}


I encountered some challenges while finding the "right way"
- no easy way to "apply"
- countif/equality not working here
- *()&(SFHKJHSF(&(*&:>( code tags!!

### #9m3mb3rsh1p

Posted 12 October 2012 - 05:52 PM

Hi. I'm also a beginner so I thought I'd share my solution. I'm stuck at how to count the flips without loops because I don't quite yet have a firm grasp of the Java utils.

I enjoyed this. Thanks to all

[source lang="java"]

import java.util.Random;
import java.util.Arrays;
import java.util.Collections;

public class Coin
{
public enum Side { heads, tails, edge };

public Coin()
{
_side = Side.edge;
}
public Coin(Side side)
{
_side = side;
}
public Coin(Random generator)
{
flip(generator);
}
public void flip(Random generator)
{
double value = generator.nextDouble();

if(value < 0.5 )
else if(value > 0.5)
{_side = Side.tails;}
else
{_side = Side.edge;}
}
public boolean equals(Coin other)
{
return _side == other._side;
}
public String toString()
{
return _side.toString();
}
private Side _side;

public static void main(String[] args)
{
Coin tails = new Coin(Side.tails);

Random rand = new Random();

Coin[] coins = new Coin[]
{
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand)
};

System.out.println(Arrays.toString(coins));

int numTails = Collections.frequency(Arrays.asList(coins), tails);
System.out.println("There are " + numTails + " tails.");
}
}

[/source]



I encountered some challenges while finding the "right way"
- no easy way to "apply"
- countif/equality not working here
- *()&(SFHKJHSF(&(*&:>( code tags!!

### #8m3mb3rsh1p

Posted 12 October 2012 - 05:50 PM

Hi. I'm also a beginner so I thought I'd share my solution. I'm stuck at how to count the flips without loops because I don't quite yet have a firm grasp of the Java utils.

I enjoyed this. Thanks to all
[source lang="java"]
import java.util.Random;
import java.util.Arrays;
import java.util.Collections;

public class Coin
{
public enum Side { heads, tails, edge };

public Coin()
{
_side = Side.edge;
}
public Coin(Side side)
{
_side = side;
}
public Coin(Random generator)
{
flip(generator);
}
public void flip(Random generator)
{
double value = generator.nextDouble();

if(value < 0.5 )
else if(value > 0.5)
{_side = Side.tails;}
else
{_side = Side.edge;}
}
public boolean equals(Coin other)
{
return _side == other._side;
}
public String toString()
{
return _side.toString();
}
private Side _side;

public static void main(String[] args)
{
Coin tails = new Coin(Side.tails);

Random rand = new Random();

Coin[] coins = new Coin[]
{
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand)
};

System.out.println(Arrays.toString(coins));

int numTails = Collections.frequency(Arrays.asList(coins), tails);
System.out.println("There are " + numTails + " tails.");
}
}
[/source]

I encountered some challenges while finding the "right way"
- no easy way to "apply"
- countif/equality not working here

### #7m3mb3rsh1p

Posted 12 October 2012 - 05:49 PM

Hi. I'm also a beginner so I thought I'd share my solution. I'm stuck at how to count the flips without loops because I don't quite yet have a firm grasp of the Java utils.

I enjoyed this. Thanks to all

[source lang="java"]import java.util.Random;import java.util.Arrays;import java.util.Collections;public class Coin{public enum Side { heads, tails, edge };public Coin(){ _side = Side.edge;}public Coin(Side side){ _side = side;}public Coin(Random generator){ flip(generator);}public void flip(Random generator){ double value = generator.nextDouble(); if(value < 0.5 ) {_side = Side.heads;} else if(value > 0.5) {_side = Side.tails;} else {_side = Side.edge;}}public boolean equals(Coin other){ return _side == other._side;}public String toString(){ return _side.toString();} private Side _side;public static void main(String[] args){ Coin heads = new Coin(Side.heads); Coin tails = new Coin(Side.tails); Random rand = new Random(); Coin[] coins = new Coin[] { new Coin(rand), new Coin(rand), new Coin(rand), new Coin(rand), new Coin(rand), new Coin(rand), new Coin(rand), new Coin(rand), new Coin(rand), new Coin(rand) }; System.out.println(Arrays.toString(coins)); int numHeads = Collections.frequency(Arrays.asList(coins), heads); System.out.println("There are " + numHeads + " heads."); int numTails = Collections.frequency(Arrays.asList(coins), tails); System.out.println("There are " + numTails + " tails.");}}[/source]

I encountered some challenges while finding the "right way"
- no easy way to "apply"
- countif/equality not working here

### #6m3mb3rsh1p

Posted 12 October 2012 - 05:43 PM

Hi. I'm also a beginner so I thought I'd share my solution. I'm stuck at how to count the flips without loops because I don't quite yet have a firm grasp of the Java utils.

I enjoyed this. Thanks to all
[source lang="Java"]
import java.util.Random;
import java.util.Arrays;
import java.util.Collections;

public class Coin
{
public enum Side { heads, tails, edge };

public Coin()
{
_side = Side.edge;
}
public Coin(Side side)
{
_side = side;
}
public Coin(Random generator)
{
flip(generator);
}
public void flip(Random generator)
{
double value = generator.nextDouble();

if(value < 0.5 )
else if(value > 0.5)
{_side = Side.tails;}
else
{_side = Side.edge;}
}
public boolean equals(Coin other)
{
return _side == other._side;
}
public String toString()
{
return _side.toString();
}
private Side _side;

public static void main(String[] args)
{
Coin tails = new Coin(Side.tails);

Random rand = new Random();

Coin[] coins = new Coin[]
{
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand),
new Coin(rand)
};

System.out.println(Arrays.toString(coins));