Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从我的方法打印问题_Java_Methods - Fatal编程技术网

Java 从我的方法打印问题

Java 从我的方法打印问题,java,methods,Java,Methods,我是Java新手,我一直在疯狂地尝试让它工作。 在过去的几个小时里,我一直试图让这种打印方法发挥作用,但我就是不知道它到底出了什么问题。我运行它时没有收到任何错误。我只希望在完成所有计算后显示一个输出框。 我需要向用户询问以下信息,并显示以下内容的输出: 要比较的贷款数量 房价 首期付款 我的问题:我的数学出了问题,输出框显示了不止一次 我非常感谢你对我的帮助。提前谢谢 package javamortgagecalculator; import javax.swing.JOpt

我是Java新手,我一直在疯狂地尝试让它工作。 在过去的几个小时里,我一直试图让这种打印方法发挥作用,但我就是不知道它到底出了什么问题。我运行它时没有收到任何错误。我只希望在完成所有计算后显示一个输出框。 我需要向用户询问以下信息,并显示以下内容的输出: 要比较的贷款数量 房价 首期付款

我的问题:我的数学出了问题,输出框显示了不止一次

我非常感谢你对我的帮助。提前谢谢

    package javamortgagecalculator;
    import javax.swing.JOptionPane;
    public class JavaMortgageCalculator {

    public static void main(String[] args) {
    int numberOfLoans;
    double sellingPrice;
    double downPayment;
    double loanAmount;
    double annualInterestRate = 0.0;
    int numberOfYears = 0;
    double[] interestRatesArr;
    int[] numberOfYearsArr;
    double[] monthlyPayment;

    //A. Enter the Number Of Loans to compare and Convert numberOfLoansString to int
    String numberOfLoansString = JOptionPane.showInputDialog("Enter the Number Of Loans to Compare");
    numberOfLoans = Integer.parseInt(numberOfLoansString);

    //B. Enter the Selling Price of Home Convert homeCostString to double
    String sellingPriceString = JOptionPane.showInputDialog("Enter the Loan Amount");
    sellingPrice = Double.parseDouble(sellingPriceString);

    //C. Enter the Down Payment on the Home
    String downPaymentString = JOptionPane.showInputDialog("Enter the down payment on the Home");
    downPayment = Double.parseDouble(downPaymentString);

    //Get the loanAmount by Subtracting the Down Payment from homeCost
    loanAmount = sellingPrice - downPayment;

    interestRatesArr = new double[numberOfLoans];
    numberOfYearsArr = new int[numberOfLoans];
    monthlyPayment = new double[numberOfLoans];
    int counter = 1;

    for (int i = 0; i < numberOfLoans; i++) {
        //Enter the Interest Rate
        String annualInterestRateString = JOptionPane.showInputDialog("Enter the interest rate for Scenario " + counter);
        annualInterestRate = Double.parseDouble(annualInterestRateString);
        interestRatesArr[i] = (annualInterestRate);

        //D2 Get the number of years
        String numberOfYearsString = JOptionPane.showInputDialog("Enter the number of years for Scenario " + counter);
        numberOfYears = Integer.parseInt(numberOfYearsString);
        numberOfYearsArr[i] = (numberOfYears);

        counter++;
    }

    printArray(numberOfLoans,
    sellingPrice,
    downPayment,
    loanAmount,
    annualInterestRate,
    numberOfYears,
    interestRatesArr,
    numberOfYearsArr,
    monthlyPayment);

}


//public static void printArray(int numOfLoans, double price, double dwnPayment, double loanAmt, double[] printRate, int[] printYears) {

  public static void printArray(int numberOfLoans2,
    double sellingPrice2,
    double downPayment2,
    double loanAmount2,
    double annualInterestRate2,
    int numberOfYears2,
    double[] interestRatesArr2,
    int[] numberOfYearsArr2,
    double[] monthlyPayment2){


    for (int i = 0; i < numberOfLoans2; i++) {
        //Calculate monthly payment
        double monthlyPayment = loanAmount2 * annualInterestRate2 / (1 - 1 / Math.pow(1 + annualInterestRate2, numberOfYears2 * 12));
        //Format to keep monthlyPayment two digits after the decimal point
        monthlyPayment = (int) (monthlyPayment * 100) / 100.0;
        //Store monthlyPayment values in an array
        monthlyPayment2[i] = (monthlyPayment);

        //Calculate total Payment
        double totalPayment = monthlyPayment2[i] * numberOfYears2 * 12;

        //Format to keep totalPayment two digits after the decimal point
        //totalPayment = (int) (totalPayment * 100) / 100.0;
        //totalPaymentArray[i] = (totalPayment);

        StringBuilder sb = new StringBuilder();
        int n = 0;
        for (int x = 0; x < numberOfLoans2; x++) {
            if (n == 0) {
                sb.append(String.format("%s\t\t %s\t\t %s\t\t %s\t\t %s\t\t %s\t\t %n", "Selling Price", "Down Payment", "Loan Amount", "Rate", "Years", "Payment"));
            }
            sb.append(String.format("%s\t\t\t\t %s\t\t\t\t\t\t %s\t\t\t\t\t\t\t\t %s\t\t\t\t\t\t\t\t %s\t\t\t\t\t\t %s\t\t\t\t %n", "$" + sellingPrice2, "$" + downPayment2, "$" + loanAmount2, interestRatesArr2[i] + "%", numberOfYearsArr2[i], "$" + monthlyPayment2[i]));
            n++;
        }

        String toDisplay = sb.toString();

        JOptionPane.showMessageDialog(null, sb.toString(), toDisplay, JOptionPane.INFORMATION_MESSAGE);
    }

}
package计算器;
导入javax.swing.JOptionPane;
公共类计算器{
公共静态void main(字符串[]args){
国际货币基金组织贷款;
双重销售价格;
双倍首付;
双loanAmount;
双年度利率=0.0;
int numberOfYears=0;
双[]利率;
int[]年数r;
双倍[]月付款;
//A.输入要比较的贷款数量,并将numberOfLoansString转换为int
String numberOfLoansString=JOptionPane.showInputDialog(“输入要比较的贷款数量”);
numberOfLoansString=Integer.parseInt(numberOfLoansString);
//B.输入房屋的售价,将homeCostString转换为double
String sellingPriceString=JOptionPane.showInputDialog(“输入贷款金额”);
sellingPrice=Double.parseDouble(sellingPriceString);
//C.在房屋上输入首付款
String downPaymentString=JOptionPane.showInputDialog(“在房屋上输入首付款”);
首期付款=Double.parseDouble(首期付款字符串);
//通过从房屋成本中减去首付款获得贷款金额
loanAmount=销售价格-首付款;
利息SAR=新的双倍[贷款数量];
numberOfYearsArr=新的整数[numberOfLoans];
月付款=新的双倍[贷款数量];
int计数器=1;
对于(int i=0;i

}

请确定此代码与您前面的问题有何不同,可能是的重复项,也可能是的重复项,以及。