-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriverMain.java
More file actions
48 lines (43 loc) · 1.75 KB
/
driverMain.java
File metadata and controls
48 lines (43 loc) · 1.75 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
/**
* This program tests the Coin and subCoin classes.
* @author Michael Chadwick
* @version 2/20/20
*/
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class driverMain
{
public static void main(String[] args)
{
Coin[] coin = new Coin[]{new Coin(), new Coin(), new Coin(), new Coin(), new Coin(), new Coin(), new Coin()}; //create an array of seven coins
int[] values = new int[]{1, 5, 10, 25, 50}; //creats array with the varrying monetary value of potential coins
Random generator = new Random();
int headsFlipped = 0; //counts the number of coins that landed on Heads
int headsSum = 0; //sums the total monetary value of the coins that landed on Heads
int headsValue = 0; //current value of last Heads flipped
int tailsValue = 0; //current value of last Tails flipped
for(int i = 0; i != coin.length; i++)
{
coin[i].flipCoin();
int index = generator.nextInt(values.length);
if(coin[i].getFace() == true)
{
headsFlipped++;
headsValue = values[index];
headsSum += headsValue;
subCoin c = new subCoin(headsValue);
System.out.println(coin[i].toString(true) + "\t" + headsValue + "\t" + c.toString());
}
else
{
tailsValue = values[index];
subCoin c = new subCoin(tailsValue);
System.out.printf(coin[i].toString(false) + "\t" + tailsValue + "\t" + c.toString() + "\n");
}
}
System.out.println("The number of heads:" + headsFlipped);
System.out.println("The total value of heads:" + headsSum);
}
}