Try this. I think you should recalculate the total money. Because number of shops is 21, is correct. Please recalculate total money; it can never be 210000.
public class investmentCalculation {
private int income;
private int shop;
private int firstMoney;
private int totalMoney1;
private int shopsAdded;
public investmentCalculation() {
income = 10000;
shop = 3;
firstMoney = 30000;
totalMoney1 = 0;
shopsAdded = 0;
}
// here the method to achieve the goal
public int SetFor() {
for (int i = 0; i < 7; i++) {
totalMoney1 += income * shop;
shopsAdded = totalMoney1 / firstMoney; //Calculate how many shops can be added with the money you have.
shop += shopsAdded; //Increment the shops by the newly added shops.
totalMoney1 -= firstMoney * shopsAdded; //Decrement the cost required to form the new shops.
}
System.out.println("the total money is: " + totalMoney1);
return shop;
}
/** this class to test the investmentCalculation */
public static void main(String[] args) {
investmentCalculation TT = new investmentCalculation();
int A = TT.SetFor();
System.out.println("the shops are: " + A);
}
}`