Need some help creating a class
in
Programming Questions
•
9 months ago
Hi all. I'm trying to create a class in Processing based on some code I wrote in Python (for EdX MIT 6.00x - the best course I've ever taken online). I've pasted the code below. The error I'm running into involves getting Processing to return an instance of a class.
class SimpleVirus {
float popDensity;
float maxBirthProb;
float clearProb;
SimpleVirus(float self_maxBirthProb, float self_clearProb) {
maxBirthProb = self_maxBirthProb;
clearProb = self_clearProb;
}
float getMaxBirthProb() {
return maxBirthProb;
}
float getClearProb() {
return clearProb;
}
boolean doesClear() {
if (random(0, 1) < clearProb) {
return true;
} else {
return false;
}
}
object reproduce() {
if (random(0,1) < (maxBirthProb * (1- popDensity))) {
newVirus = new SimpleVirus(maxBirthProb, clearProb);
return newVirus;
} else {
print("NoChildException");
}
}
}
Now clearly object isn't a viable variable and class can't be used either. Any ideas on how I can set this method up to generate a new instance of the SimpleVirus class and then return it. Thanks for any help. If my request isn't clear, please let me know and I will try to clarify.
1