Я новичок в программировании и не совсем понимаю, как создать калькулятор аннуитета, который обрабатывает как долги, так и данные об инвестициях, используя только циклы.
`import java.util. *;
public class AnnuityLoop {
public static void main(String[] args){
//State variables for investment details
double calculateMonthlyInvestment = 0;
int termYears;
double interestRate = 0;
double interest;
double monthlyInvestment = 0;
int numberOfloops;
double principleAmount = 0;
String userSelection = ""; //string to process the user's selection
// Monthly interest rate is the yearly rate divided by 12
// The length of the term in months is the number of years times 12
// console input from the user
Scanner inputScanner = new Scanner(System.in);
// Prompt the user for information about the investment or debt
System.out.println("Would you like to perform a calculation for an investment or a debt? (type 1 for an investment and 2 for a debt calculation)");
if (userSelection.equals("1")){
System.out.println("Enter investment amount: ");
principleAmount = inputScanner.nextDouble();
System.out.println("Enter investment term in years: ");
termYears = inputScanner.nextInt();
System.out.println("Enter interest rate: ");
interest = inputScanner.nextDouble();
interestRate = interest / 100.0;
double monthlyRate = interestRate / 12.0;
System.out.println("Enter the monthly investment");
monthlyInvestment = inputScanner.nextDouble();
// Loop for the number of terms
double futureValue = principleAmount;
for (int i = 0; i < termYears*12; i--){
futureValue = (futureValue * (1 + monthlyRate))+ monthlyInvestment;
System.out.println("Your calculated amount is: " + futureValue + ".");
}
else if (userSelectioon.equals("2")){
} } } `
Если у вас есть какие-либо советы по поводу моего кода или информация о том, как создать калькулятор аннуитетного долга с использованием циклов, дайте мне знать.
Обновление, я понял, что мне нужно сохранить основную сумму для будущего значения суммы: