invulve people and diseases bugs 2 Person Class 15 marks Com
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](/WebImages/27/invulve-people-and-diseases-bugs-2-person-class-15-marks-com-1074307-1761563220-0.webp)
![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](/WebImages/27/invulve-people-and-diseases-bugs-2-person-class-15-marks-com-1074307-1761563220-1.webp)
