The code below is for figuring out a loan from user input. I seem to be having trouble with the code towards the bottom. I can not get my output statesment to be in currency format and it says some of the outputs are NaN? please help i have highlighted the area i think the problem is in.
import java.util.*; import java.io.*; import java.text.*; public class Item1 { public static void main(String[] args) throws NumberFormatException { String loanS; char loan; String creditS; char credit; double moneyBorrow; double timeYears; double serviceCharge= 0; double loanRate=0; boolean goodData=true; Scanner scan = new Scanner (System.in); DecimalFormat decF = new DecimalFormat ("#,###,###.##"); System.out.println("What type of loan do you want:" +"\n\t (F)irst Home Loan" +"\n\t(H)omeImprovementLoan" +"\n\t (C)ar Loan" +"\n\t (P)ersonal Loan" +"\n\t (B)usiness Loan"); System.out.println ("Enter your choice"); loanS = scan.next(); loan= loanS.charAt(0); System.out.println ("choice is " + loan); switch(loan){ case 'F': case 'f': loanRate=4.75/100/12; break; case 'H': case 'h': loanRate=5.25/100/12; break; case 'C': case 'c': loanRate=8.25/100/12; break; case 'P': case 'p': loanRate=9.5/100/12; break; case 'B': case 'b': loanRate=6/100/12; default: goodData=false; } if(goodData=false){ System.out.println("Incorrect Data"); } System.out.println("What is your credit status" +"\n\t(P)oor" +"\n\t(F)air" +"\n\t(G)ood" +"\n\t(E)xcellent"); creditS = scan.next(); credit= creditS.charAt(0); System.out.println("Answer: "+ credit); System.out.println("How many thousands of dollars would you like to borrow?"); moneyBorrow = scan.nextDouble(); System.out.println("How many years will it take to pay off loan?"); timeYears= scan.nextDouble()*1000; double moneyBorrowed =moneyBorrow *1000; System.out.println(moneyBorrowed); switch(credit) { case'P': case'p': serviceCharge=.03*moneyBorrowed; break; case'F': case'f': serviceCharge=.02*moneyBorrowed; break; case'G': case'g': serviceCharge=.01*moneyBorrowed; break; case'E': case'e': } // Monthly payment = (mIR * LoanAmount) / (1 - (1 / (1+mIR)^(12*TimeInYears) ) ) //mIR = monthly interest rate = annual interest rate /12 //TimeInYears = number of years needed to pay off loan [COLOR="Blue"]moneyBorrowed=moneyBorrowed+serviceCharge; int mIR=0; double monthlyPay =(mIR*moneyBorrowed)/(1-(1/Math.pow((1+mIR),(12*timeYears)))); double loanTotal=monthlyPay*timeYears*12; double interestPaid=loanTotal-moneyBorrowed; double interestPercent=interestPaid/loanTotal*100;[/COLOR] NumberFormat currF = NumberFormat.getCurrencyInstance(); NumberFormat percentF = NumberFormat.getPercentInstance(); System.out.println(percentF.format(mIR)); System.out.println(currF.format(monthlyPay)); System.out.printf("interestRate: %11.2f%n",loanRate*100*12); System.out.printf("Loan Amount: %11.2f%n",moneyBorrowed); System.out.printf("Monthly Payment: %11.2f%n",monthlyPay); System.out.printf("Total Amount Paid:%11.2f%n",loanTotal); System.out.printf("Total Interest Paid: %11.2f%n",interestPaid); System.out.printf("Interest Paid as a percent of loan: %11.2f%n",interestPercent); // int timeInYears = [/color]