-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin.java
More file actions
49 lines (42 loc) · 1.22 KB
/
Coin.java
File metadata and controls
49 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* This class constructs a coin and simulates the flipping of said coin.
* @author Michael Chadwick
* @version 2/20/2020
*/
import java.util.Random;
public class Coin
{
boolean face;
Random randomF = new Random();
/**
* Constructs a new coin object and calls the flipCoin method.
*/
public Coin()
{
flipCoin(); // initialise instance variable
}
/**
* Determines the coins facing ie Heads or Tails.
*/
public void flipCoin()
{
face = randomF.nextBoolean(); //populate face
}
/**
* This method returns the coins face value.
* @return face - the coins face; either Heads or Tails.
*/
public boolean getFace()
{
return face; //return face
}
/**
* This meathod checks the boolean value of face and returns the string value "Heads" if it's true, and "Tails" if it's false.
*@param boolean - the face of the coin
*@return Heads/Tails - if true returns the string "Heads" else(ie false) returns the string "Tails".
*/
public String toString(boolean face)
{
return(face == true) ? "Heads" : "Tails"; //check for true or false. If true execute 1st case if false execute 2nd.
}
}