(() => {
class Country
{
constructor({ tax_rate, networth, land, ent, bus_tech, gvt_pci_bonus, population })
{
this.tax_rate = tax_rate;
this.networth = networth;
this.land = land;
this.ent = ent;
this.bus_tech = bus_tech;
this.gvt_pci_bonus = gvt_pci_bonus;
this.population = population;
}
getPCI()
{
return this.getTwoDecimalRound(
22.5
* (1 - this.tax_rate)
* (1 + ((this.networth/this.land)/18000))
* (1 + (2 * (this.ent/this.land)))
* this.bus_tech
* this.gvt_pci_bonus
);
}
getRevenue()
{
return Math.round(this.getPCI() * this.population * this.tax_rate);
}
getTwoDecimalRound(val)
{
return (Math.round(val*100))/100;
}
}
const country = new Country({
tax_rate: 0.35,
networth: 4708,
land: 100,
ent: 0,
bus_tech: 1,
gvt_pci_bonus: 1,
population: 803
});
console.log(country.getPCI());
console.log(country.getRevenue());
})();
Output:
14.66
4120
Numbers work for me.
Note: The function with (val*100)/100 is required due to precision bug in all coding languages.