iceblits
Active Member
- Joined
- May 10, 2007
- Sythe Gold
- 0
- Messages
- 135
I'm trying to make a loan program that calculates the number of months it takes to pay off a loan while also printing out the Payment, Balance, Interest, and Principle. Heres what I have so far..
its stuck in an infinite loop for some reason....
Code:
import javax.swing.*;
import java.awt.*;
import javax.swing.JOptionPane.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class MonthlyPayment {
public static void main(String[] args) {
// Declaration of variables
double I; // Monthly interest rate
double Balance = (double) -1; // Amount borrowed
double InterestRate = (double) -1; // Annual interest rate
double MonthlyPayment = (double) -1; // Monthly payment
double Interest; // Amount owed through interest
double TotalInterest=(double) 0; //
double Principle=(double) 0; // Part that goes towards paying off the loan
int Payment=0;
NumberFormat form;
DecimalFormat DF=new DecimalFormat("###00");
form=NumberFormat.getCurrencyInstance();
// Prompting the user for the loan, annual interest, and monthly payment
while (Balance <= 0) { // Prompting positive value greater than zero
String Prompt = "Enter the Loan Amount:";
String Data = JOptionPane.showInputDialog(Prompt, "0");
if (Data == null)
return;
Balance = Double.parseDouble(Data);
}
while (InterestRate <= 0) {
String Prompt = "Enter the Annual Interest Rate:";
String Data = JOptionPane.showInputDialog(Prompt, "0");
if (Data == null)
return;
InterestRate = Double.parseDouble(Data);
}
while (MonthlyPayment < 0) {
String Prompt = "Enter the Monthly Payment:";
String Data = JOptionPane.showInputDialog(Prompt, "0");
if (Data == null)
return;
MonthlyPayment = Double.parseDouble(Data);
}
//calculations
I=InterestRate/12;
System.out.println();
while(Balance>MonthlyPayment){
Interest=Balance*I;
TotalInterest=TotalInterest+Interest;
Principle=MonthlyPayment-Interest;
System.out.println(Payment+""+DF.format(Balance)+""+DF.format(Interest)+""+DF.format(Principle));
Payment=Payment+1;
}
}
}
its stuck in an infinite loop for some reason....


