Created
September 14, 2010 22:47
-
-
Save jbn/579918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
/* | |
Curves: | |
probabilityOfHavingChild(deltaWealth, inflation) | |
wealth/inflation | |
consumptionCurve(deltaWealth, inflation) | |
adolesentConsumptionRequirements | |
adulthoodBetsowment | |
adulthoodYearlyExpense | |
*/ | |
public class Individual{ | |
public static void main(String[] args){ | |
Individual individual = new Individual(40, 10000000.0); | |
for(int i=0; i<100; ++i){ | |
individual.ageOneYear(Math.random()/10.0 - 0.05); | |
System.out.println(individual.getWealth()); | |
} | |
} | |
private int age; | |
private double wealth; | |
private LinkedList<Individual> children; | |
public Individual(){ | |
this(0,0.0); | |
} | |
public Individual(int age, double wealth){ | |
this.age = age; | |
this.wealth = wealth; | |
children = new LinkedList<Individual>(); | |
} | |
public double getWealth(){ | |
return wealth; | |
} | |
void inheritWealth(double inheritance){ | |
wealth += inheritance; | |
} | |
/** | |
@param returnOnWealth [-1,1] as %return/100 | |
*/ | |
public void ageOneYear(double returnOnWealth){ | |
++age; | |
wealth *= 1.0+returnOnWealth; | |
for(Individual individual : children){ | |
ageOneYear(returnOnWealth); | |
} | |
} | |
protected boolean hasDied(){ | |
if(age+Math.random()*10 > 70 && Math.random() < 0.1){ | |
double amountPerChild = wealth / children.size(); | |
for(Individual child : children) | |
child.inheritWealth(amountPerChild); | |
wealth = 0.0; | |
} | |
return true; | |
} | |
protected boolean hasChild(){ | |
if(age > 20 && children.size() < 5 && Math.random() < 0.01666){ | |
double trustFund = 0.05 * wealth; | |
wealth = 0.95 * wealth; | |
children.add(new Individual(0, wealth)); | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment