Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class A2Q2 {
- public static void main (String[] args) {
- //delcare new variables
- Scanner kbd = new Scanner(System.in);
- int days;
- //these amounts change
- int susceptible;
- int exposed;
- int infectious;
- int recovered;
- //constants inputted by user
- double contact;
- double latency;
- double recovery;
- exposed = 0;
- recovered = 0;
- //get input from the user to calculate the amount of people susceptible, exposed, infectious and recovered.
- System.out.print ("How many days long will your simulation be?");
- days = kbd.nextInt();
- System.out.print ("Input the number of susceptible people:");
- susceptible = kbd.nextInt();
- System.out.print ("Input the number of infected people:");
- infectious = kbd.nextInt();
- System.out.print ("Input the contact rate:");
- contact = kbd.nextDouble();
- System.out.print ("Input the latency rate:");
- latency = kbd.nextDouble();
- System.out.print ("Input the recovery rate:");
- recovery = kbd.nextDouble();
- //declare new variables for calculating the amount of susceptible, exposed, infectious and recovered.
- double susceptibleChange;
- double exposedChange;
- double infectiousChange;
- double recoveredChange;
- //calculates changes
- susceptibleChange = ((-contact) * infectious * susceptible);
- exposedChange = (contact * infectious * susceptible) - (latency * exposed);
- infectiousChange = (latency * exposed) - (recovery * infectious);
- recoveredChange = (recovery * infectious);
- //delcare new loop variable
- int i;
- //start for loop
- for (i = 1; i <= days; i++) {
- /*these variables are printed in the final output and calculated by adding the change variable to the
- * initial variable */
- double susceptibleUpdate;
- double exposedUpdate;
- double infectiousUpdate;
- double recoveredUpdate;
- //updates the values to be outputted
- susceptibleUpdate = (susceptible) + (susceptibleChange);
- exposedUpdate = (exposed) + (exposedChange);
- infectiousUpdate = (infectious) + (infectiousChange);
- recoveredUpdate = (recovered) + (recoveredChange);
- //final output
- System.out.println ("Day " + i + ":\n"
- + " Number Susceptible: " + Math.round(susceptibleUpdate) +
- "\n Number Exposed: " + Math.round(exposedUpdate) +
- "\n Number Infectious: " + Math.round(infectiousUpdate) +
- "\n Number Recovering: " + Math.round(recoveredUpdate));
- }//close for loop
- }
- }
Add Comment
Please, Sign In to add comment