In my class, i have to calculate prices of 18 different building which have different prices and income. They also have changes in price when the money of quantity of the building increases.
For example: The building starts at 40 dollars when the quantity is 0. The price increments by 4 for each quantity. So if you own 1, the price to buy the next same building will be 44 in state of 40. So this is the method that will calculate the price just fine.
public float getBuildingPrice(float quantity)
{
float buildingNum = quantity;
float startingPrice = 40;
float costIncrease = 4;
float finalPrice;
finalPrice = startingPrice + (costIncrease*buildingNum);
return finalPrice;
}
The method above returns the price and i divided the calculated price with the income that comes to the building like this. 10 is the income
float storageWorth = buildingPrice/10;
The thing i am unable to do is to find out the amount of different building the user can buy in the most efficient way ( meaning highest income but lowest spending ) So it should be the lowest Price / income that should be fulfilling the condition but also keeping in mind that it must be in the budget that the user keys in. There is always a change in the price and i do not know how to compare multiple values ( 18 values ) with the extra condition to keep in the budget.
For example
Farm
- Income - 1
- 5 buildings
- Increment of 4
- Price 40 + (5 * 4) = 60 Price over income = 60
Pen
- Income - 5
- 4 Buildings
- Increment of 20
- Price 200 + (4 * 20) = 280 Price over income 280/5 = 56
So meaning to say the next building the user should buy is a pen because it has lower price/income. There is also chances that the price over income of both building is the same like if the building reaches 5 for pen building, both price over income of pen and farm will be 60.