Personjava is givenSolutionSince I didnt have the implementa

Person.java is given

Solution

Since I didn\'t have the implementation of the Disease class, I made some assumptions and wrote the code accordingly.

public class Person{
    public final String name;
    protected int health;
    protected Disease[] diseases;

    public Person(String name, int health){
        this.name = name;
        this.health = health;
    }

    public int getHealth(){
        return this.health;
    }

    public void addDisease(Disease dis){
        if (!diseasePresent(dis)){
            Disease[] updated_diseases[diseases.length+1] = new Disease[];
            for (int i<0; i<diseases.length; i++){
                updated_diseases[i] = diseases[i]
            }
            updated_diseases[diseases.length] = dis;
        }
    }

    public boolean diseasePresent(Disease disease){
        for (Disease d: diseases){
            if (d.name == disease.name){
                return true;
            }
        }
        return false;
    }

    public void interact(Person other){
        System.err.println(\"log: \" + name + \" interacts with \" + other.name);
        for (Disease d: this.diseases){
            if (Math.random()<d.chance_of_transmitting){
                Disease dis = new Disease(d.name, severity, chance_of_transmitting);
                other.addDisease(dis);
            }
        }

        for (Disease d: other.diseases){
            if (Math.random()<d.chance_of_transmitting){
                Disease dis = new Disease(d.name, severity, chance_of_transmitting);
                this.addDisease(dis);
            }
        }

    }

    public void interact(Insect bug, double probability){
        System.err.println(\"log: \" + name + \" inteacts with\" + bug.name + \"(insect)\");

        if (Math.random()<probability){
            bug.bite(this);
        }
    }
}

Person.java is givenSolutionSince I didn\'t have the implementation of the Disease class, I made some assumptions and wrote the code accordingly. public class P
Person.java is givenSolutionSince I didn\'t have the implementation of the Disease class, I made some assumptions and wrote the code accordingly. public class P

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site