invulve people and diseases bugs 2 Person Class 15 marks Com

invulve people, and diseases bugs 2: Person Class 15 marks] Complete the provided Person class. Add appropriate getter and setter methods. Complete the interact (Person) method. when a person transmits a disease to another person, a new copy of the same disease should be transmitted (same name, severity, chance of transmission). Make sure that you create a new Disease object. (why?) Put your Person ava file in your assignment5.zip file.

Solution

Modified code:

public class Person {

   public final String name;

   protected int health;

   protected Disease diseases[];

  

   //constructor for the class Person

   public Person(String name, int health) {

       this.name = name;

       this.health = health;

   }

   //getters and setters for the class Person

   public int getHealth() {

       return health;

   }

   public void setHealth(int health) {

       this.health = health;

   }

   public Disease[] getDiseases() {

       return diseases;

   }

   public void setDiseases(Disease[] diseases) {

       this.diseases = diseases;

   }

   public String getName() {

       return name;

   }

  

   //interact method modified with the requirements

   public void interact(Person other)

   {

       if(this.diseases.length > 0)

       {

           for(int i=0; i<this.diseases.length; i++)

           {

               if(diseases[i].isCommunicableDisease)

               {

                   int otherPersonDiseaseCount = other.getDiseases().length; // this will give the index on which the new disease should be added

                   other.diseases[otherPersonDiseaseCount] = new Disease(); // creating a new object for the particular disease

                   other.diseases[otherPersonDiseaseCount] = diseases[i]; // adding disease from this person to other person

                   other.diseases[otherPersonDiseaseCount].chance_of_probabilty(\"*\"); // setting the probability

               }

           }

       }

       if(other.diseases.length > 0)

       {

           for(int i=0; i<other.diseases.length; i++)

           {

               if(other.diseases[i].isCommunicableDisease)

               {

                   int thisPersonDiseaseCount = this.getDiseases().length; // this will give the index on which the new disease should be added

                   this.diseases[thisPersonDiseaseCount] = new Disease(); // creating a new object for the particular disease

                   this.diseases[thisPersonDiseaseCount] = other.diseases[i]; // adding disease from this person to other person

                   this.diseases[thisPersonDiseaseCount].chance_of_probabilty(\"*\"); // setting the probability

               }

           }

       }

       System.err.println(\"log: \" + name + \" interacts with \" + other.getName());

   }

}

 invulve people, and diseases bugs 2: Person Class 15 marks] Complete the provided Person class. Add appropriate getter and setter methods. Complete the interac
 invulve people, and diseases bugs 2: Person Class 15 marks] Complete the provided Person class. Add appropriate getter and setter methods. Complete the interac

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site