Advertisement
Guest User

Untitled

a guest
May 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1.  
  2.  
  3. package com.three_x_aught_one;
  4.  
  5. public class BacteriaReproduction {
  6. public static void bacteriaReproduction(int bacteriaAMT, int hours, double probability){
  7. int hourTries = 0;
  8. if(!(bacteriaAMT <= 0 || hours <= 0 )){
  9. while(bacteriaAMT > 0 && hourTries <= hours ){
  10. for(int tries = bacteriaAMT; tries == 0; tries--){
  11. if(Math.random() >= probability){
  12. bacteriaAMT++;
  13. System.out.println("Bacteria: " + bacteriaAMT + " | Hours: " + hourTries + "/" + hours);
  14. hourTries++;
  15. } else {
  16. bacteriaAMT--;
  17. System.out.println("Bacteria: " + bacteriaAMT + " | Hours: " + hourTries + "/" + hours);
  18. hourTries++;
  19. }
  20. }
  21. }
  22. } else {
  23. System.out.print("Invalid Parameters");
  24. }
  25. }
  26. }
  27.  
  28. package com.three_x_aught_one;
  29. import java.lang.Math;
  30. import java.util.Scanner;
  31.  
  32. public class Main extends BacteriaReproduction{
  33.  
  34. public static void main(String[] args) {
  35. Scanner scan = new Scanner(System.in);
  36. System.out.print("INT: Hours for bacteria reproduction: ");
  37. int hours = scan.nextInt();
  38. System.out.print("INT: Amount of starting bacteria: ");
  39. int bacteriaAMT = scan.nextInt();
  40. System.out.print("DOUBLE: Probability of death: ");
  41. double probability = scan.nextDouble();
  42. bacteriaReproduction(bacteriaAMT, hours, probability);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement