나는이 포럼과 Java에 일종의 신참이다. 나는 어려움을 겪고 있는데 사용자가 단계 D에서 비교할 대출을 하나 이상 입력하도록 요청하는 방법을 찾고 있습니다. 나는 A 단계에서 입력 한 금액에 대해 다른 이자율과 연수를 물어볼 수 있어야합니다. 그래서 10을 입력하면 10 회에 걸쳐 금리와 년간 물어봐야합니다. 탭을 사용하여 테이블 형식으로. 어떤 도움이라도 대단히 감사합니다. 미리 감사드립니다.두 개 이상의 자바 입력
편집 : 도움을 주셔서 대단히 감사합니다. 코드를 업데이트했습니다.
//A. Enter the Number Of Loans to compare
String numberOfLoansString = JOptionPane.showInputDialog("Enter the amount of loans to compare:");
//Convert numberOfLoansString to int
int numberOfLoans = Integer.parseInt(numberOfLoansString);
//B. Enter the Amount/Selling Price of Home
String loanAmountString = JOptionPane.showInputDialog("Enter the loan amount:");
//Convert loanAmountString to double
double loanAmount = Double.parseDouble(loanAmountString);
//C. Enter the Down Payment on the Home
String downPaymentString = JOptionPane.showInputDialog("Enter the down payment on the Home:");
double downPayment = Double.parseDouble(downPaymentString);
//D. Ask the following for as many number of loans they wish to compare
//D1 Get the interest rate
double[] anualInterestRatesArray = new double[numberOfLoans];
double[] monthlyInterestRateArray = new double[numberOfLoans];
int[] numberOfYearsArray = new int[numberOfLoans];
double[] monthlyPaymentArray = new double[numberOfLoans];
double[] totalPaymentArray = new double[numberOfLoans];
for (int i=0; i < numberOfLoans; i++)
{
String annualInterestRateString = JOptionPane.showInputDialog("Enter the interest rate:");
double annualInterestRate = Double.parseDouble(annualInterestRateString);
anualInterestRatesArray[i] = (annualInterestRate);
//Obtain monthly interest rate
double monthlyInterestRate = annualInterestRate/1200;
monthlyInterestRateArray[i] = (monthlyInterestRate);
//D2 Get the number of years
String numberOfYearsString = JOptionPane.showInputDialog("Enter the number of years:");
int numberOfYears = Integer.parseInt(numberOfYearsString);
numberOfYearsArray[i] = (numberOfYears);
//Calculate monthly payment
double monthlyPayment = loanAmount * monthlyInterestRate/(1 - 1/Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
//Format to keep monthlyPayment two digits after the decimal point
monthlyPayment = (int)(monthlyPayment * 100)/100.0;
//Store monthlyPayment values in an array
monthlyPaymentArray[i] = (monthlyPayment);
//Calculate total Payment
double totalPayment = monthlyPaymentArray[i] * numberOfYears * 12;
//Format to keep totalPayment two digits after the decimal point
totalPayment = (int)(totalPayment * 100)/100.0;
totalPaymentArray[i] = (totalPayment);
}
왜 루프를 사용하고 있지 않습니까? 똑같은 코드를 계속해서 반복해서 실행하고 싶습니까? –
질문이 있으십니까? –
모두 도와 주셔서 감사합니다! 나는 그것을 매우 감사한다! 코드를 업데이트했습니다. 너희들에게 어떻게 보이 나? 외모가 좋으면 결과물을 출력해야합니다. For 루프 내에서 배열 값을 어떻게 호출합니까? – PittsburghCoder