 |
|
|
Flu.java
|
/**
*
* @author Havard Rast Blok
*
*/
public class Flu implements Virus, Cloneable {
/**
* The name of this Flue.
*/
protected String name;
/**
* The Host which this intance of the Flu has infected.
*/
protected Host host;
/**
* Constructs a Flu with the specified name.
* @param name
*/
public Flu(String name) {
this.name = name;
}
/*
*
* @see Virus#infect(Host)
*/
public void infect(Host host) {
//if this Virus has already infected
//the incoming host, do nothing
if(this.host == host) {
return;
}
//see if the given host is to be infected
double probability = host.transmitProbability(this.host);
if (Math.random() < probability) {
// clone this virus
Flu clone = null;
clone = (Flu) this.clone();
// infect the given host
host.addVirus(clone);
clone.host = host;
}
}
/*
* Clones this Flu.
* Returns a Flu object with the same name.
* @see java.lang.Object#clone()
*/
public Object clone() {
return new Flu(this.name);
}
}
|
|
|
 |