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

Assisting Tutor

Related Homework Solutions

Custom String Builder in Java
Homework Solution
$75.00
Java
Programming
String Builder
Algorithms
Loops
Variables
Statements
Arrays
Characters
Functions
Classes
Exception Handling
K Means Clustering in Java
Homework Solution
$65.00
Computer Science
Java Programming
K Means Clustering
Points
Greedy Implementation
Algorithms
Data Sets
Distances
Performances
Centroid
Subsets
Pseudocodes
Minimization
Java Programming Problems
Homework Solution
$38.00
Computer Science
Programming
Java
Consumers
Producers
Buffers
Waiting
Mutual Exclusion
Threads
Manipulation
Statements
Variables
Functions
Classes
Input
Output
Route Cipher in Java
Homework Solution
$30.00
Java
Programming
Computer Science
Route Cipher
Variables
Loops
Functions
Matrices
Columns
Encryption
Decryption
Clustering Problems in Java
Homework Solution
$60.00
Computer Science
Java Programming
Algorithms
Clustering
K Means
Real Factors
Voronoi Diagram
Toy Problem
Brute Force
Centroids
Iterations
Statements
Variables
Java Programming Problems
Homework Solution
$50.00
Computer Science
Java Programming
Book Objects
Buttons
Records
Database
Helper Functions
Functions
Statements
Variables
GUI
UML Diagrams
Events
Prices
Get help from a qualified tutor
Live Chats