Subject Computer Science Java Programming

Question

You will write a program which will do the following:

Ask the user to input the number of life cycles.
Keep an array of the population on each life cycle.
Start your population at 10.
The rules for each life cycle are as follows:
Roll a six sided die.
If the roll is a 1, a person was born. Add 1 to your population and update the array.
If the roll is a 2, twins were born. Add 2 to your population and update array.
If you roll a 3 or 4, no one was born or died. The population stays the same and update the array.
If the roll is a 5, someone died. Subtract 1 from your population and update the array.
If the roll is 6, a plague has struck...roll again to see how many died, subtract that number from the population and update the array.
If your population reaches zero, the simulation ends.
After the simulation finishes, print out the number of cycle and the population for that cycle.



Sample Output


Enter the number of cycles to simulate:40

Twins Born
Plague! 4 died.
Nothing Happened...
Nothing Happened...
Nothing Happened...
1 Died
Plague! 1 died.
Nothing Happened...
Twins Born
1 Birth
Twins Born
1 Birth
1 Birth
Nothing Happened...
Nothing Happened...
Nothing Happened...
1 Died
1 Died
1 Died
Twins Born
1 Birth
Twins Born
Nothing Happened...
Nothing Happened...
1 Birth
Twins Born
Nothing Happened...
Plague! 2 died.
1 Birth
1 Birth
Twins Born
Nothing Happened...
Plague! 3 died.
Nothing Happened...
Nothing Happened...
1 Birth
Twins Born
Twins Born
Plague! 4 died.
1 Died
1 - 12
2 - 8
3 - 8
4 - 8
5 - 8
6 - 7
7 - 6
8 - 6
9 - 8
10 - 9
11 - 11
12 - 12
13 - 13
14 - 13
15 - 13
16 - 13
17 - 12
18 - 11
19 - 10
20 - 12
21 - 13
22 - 15
23 - 15
24 - 15
25 - 16
26 - 18
27 - 18
28 - 16
29 - 17
30 - 18
31 - 20
32 - 20
33 - 17
34 - 17
35 - 17
36 - 18
37 - 20
38 - 22
39 - 18
40 - 17

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;


/**
*
* @author
*/
public class Driver {
    public static void main(String[] args) {
       int cycleNum;
       Scanner input = new Scanner(System.in);
       System.out.print("Enter the number of cycles to simulate: ");
       cycleNum = input.nextInt();
       // Start your population at 10.
       int population = 10;
       int roll;
       int [] array = new int[cycleNum];
       String message = "";...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$15.00

or $1 if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats