Guest User

Untitled

a guest
Jun 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class A2Q2 {
  4. public static void main (String[] args) {
  5.  
  6. //delcare new variables
  7. Scanner kbd = new Scanner(System.in);
  8. int days;
  9. //these amounts change
  10. int susceptible;
  11. int exposed;
  12. int infectious;
  13. int recovered;
  14. //constants inputted by user
  15. double contact;
  16. double latency;
  17. double recovery;
  18.  
  19. exposed = 0;
  20. recovered = 0;
  21.  
  22. //get input from the user to calculate the amount of people susceptible, exposed, infectious and recovered.
  23. System.out.print ("How many days long will your simulation be?");
  24. days = kbd.nextInt();
  25. System.out.print ("Input the number of susceptible people:");
  26. susceptible = kbd.nextInt();
  27. System.out.print ("Input the number of infected people:");
  28. infectious = kbd.nextInt();
  29. System.out.print ("Input the contact rate:");
  30. contact = kbd.nextDouble();
  31. System.out.print ("Input the latency rate:");
  32. latency = kbd.nextDouble();
  33. System.out.print ("Input the recovery rate:");
  34. recovery = kbd.nextDouble();
  35.  
  36. //declare new variables for calculating the amount of susceptible, exposed, infectious and recovered.
  37. double susceptibleChange;
  38. double exposedChange;
  39. double infectiousChange;
  40. double recoveredChange;
  41.  
  42. //calculates changes
  43. susceptibleChange = ((-contact) * infectious * susceptible);
  44. exposedChange = (contact * infectious * susceptible) - (latency * exposed);
  45. infectiousChange = (latency * exposed) - (recovery * infectious);
  46. recoveredChange = (recovery * infectious);
  47.  
  48. //delcare new loop variable
  49. int i;
  50.  
  51. //start for loop
  52. for (i = 1; i <= days; i++) {
  53.  
  54. /*these variables are printed in the final output and calculated by adding the change variable to the
  55. * initial variable */
  56. double susceptibleUpdate;
  57. double exposedUpdate;
  58. double infectiousUpdate;
  59. double recoveredUpdate;
  60.  
  61. //updates the values to be outputted
  62. susceptibleUpdate = (susceptible) + (susceptibleChange);
  63. exposedUpdate = (exposed) + (exposedChange);
  64. infectiousUpdate = (infectious) + (infectiousChange);
  65. recoveredUpdate = (recovered) + (recoveredChange);
  66.  
  67. //final output
  68. System.out.println ("Day " + i + ":\n"
  69. + " Number Susceptible: " + Math.round(susceptibleUpdate) +
  70. "\n Number Exposed: " + Math.round(exposedUpdate) +
  71. "\n Number Infectious: " + Math.round(infectiousUpdate) +
  72. "\n Number Recovering: " + Math.round(recoveredUpdate));
  73. }//close for loop
  74.  
  75. }
  76. }
Add Comment
Please, Sign In to add comment