사용자가 원하는 투자 유형 (연간, 월별 또는 분기 별)을 지정할 수있는 코드를 작성하고 있으며 각 투자 유형이 특정 정수 (예 : 연간 = 1, 월간 = 12 및 분기 별 = 4)와 관련되어 있습니다. 그러나 연간 값을 지정하면 아래의 투자 방정식에서 int 값과 상호 관련이 있어야하며이를 수행하는 방법이 완전히 부족합니다. 투자 계획의 유형에 대한 답변이되면할당 된 문자열 값을 Integer 값과 상관시키는 방법은 무엇입니까?
import java.util.Scanner;
import java.lang.Math;
public class CompoundInterest {
public static void main (String [] args)
{
Scanner cool = new Scanner (System.in);
double saving, rate;
int principal, years;
int choice;
System.out.println("Please enter you principal investment:");
/*Print statment prompts user to enter their principal investment*/
principal = cool.nextInt();
System.out.println("Would you like to have a regular investment plan?");
/* Print out statement asks user if they would like to participate in a regular investment plan*/
String question =cool.next();
System.out.println("What type of investment plan would you prefer (Annual, Quarterly, or Monthly)?");
String quest =cool.next();
while (quest.equalsIgnoreCase(("Annual")))
{ String Annual="1";
Annual.equals(choice);
}
System.out.println("Please enter the number of years that you wish to invest for:");
/* Print statement prompts user to enter the number of years that they wish to invest for*/
years = cool.nextInt();
System.out.println("Please enter the return rate per year:");
/* Print statement prompts user to enter the return rate per year*/
rate = cool.nextDouble();
saving = principal*(1+(rate/choice))* Math.pow(choice, years);
System.out.printf("%.2f", saving);
}