Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.three_x_aught_one;
- public class BacteriaReproduction {
- public static void bacteriaReproduction(int bacteriaAMT, int hours, double probability){
- int hourTries = 0;
- if(!(bacteriaAMT <= 0 || hours <= 0 )){
- while(bacteriaAMT > 0 && hourTries <= hours ){
- for(int tries = bacteriaAMT; tries == 0; tries--){
- if(Math.random() >= probability){
- bacteriaAMT++;
- System.out.println("Bacteria: " + bacteriaAMT + " | Hours: " + hourTries + "/" + hours);
- hourTries++;
- } else {
- bacteriaAMT--;
- System.out.println("Bacteria: " + bacteriaAMT + " | Hours: " + hourTries + "/" + hours);
- hourTries++;
- }
- }
- }
- } else {
- System.out.print("Invalid Parameters");
- }
- }
- }
- package com.three_x_aught_one;
- import java.lang.Math;
- import java.util.Scanner;
- public class Main extends BacteriaReproduction{
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("INT: Hours for bacteria reproduction: ");
- int hours = scan.nextInt();
- System.out.print("INT: Amount of starting bacteria: ");
- int bacteriaAMT = scan.nextInt();
- System.out.print("DOUBLE: Probability of death: ");
- double probability = scan.nextDouble();
- bacteriaReproduction(bacteriaAMT, hours, probability);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement