QuestionQuestion

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 PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use 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 = "";...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$15.00 $7.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats