I am currently in a beginning programming class. I am having problems with this exercise. We are supposed to design a program that tells how long it will take to pay off a credit card using a sentinel value to control a while loop. I have no idea what to write for my calculations, I keep getting stuck in an infinite loop. We were told that at the beginning of each month 1.3% interest is added to the balance, then the payment is 4% of the balance. When the balance is $15.00 of less the customer can pay the credit card off. The sample we are supposed to test the program with is Account # 6789A, Customer Name Jeanne Johnson, Balance 120.00. It should make a print out of the payment schedule until she can pay it off.
Thanks for any help.
Here is what I have so far:
// Payoff.java - This program prints a payoff schedule for a bank customer.
// Input: Account number, name of customer, and account balance.
// Output: Prints payoff schedule that includes payment amount and new balance
// until the account will be paid off. A customer may pay off their account when
// the balance reaches $15 or less. 1.3% interest is added at the beginning of
// each month, and the customer then makes a payment equal to 4% of the current
// balance.
import javax.swing.JOptionPane;
public class Payoff
{
public static void main(String args[])
{
// Declare and initialize variables.
String accountNumber; // Customer's account number.
String customerName; // Customer's name.
String stringBalance; // String version of balance.
double balance = 0.0; // Customer's current balance.
double sentinel = 15.00; // Controls while loop.
double interest;
double payment;
// Get input.
accountNumber = JOptionPane.showInputDialog("Enter account number: ");
customerName = JOptionPane.showInputDialog("Enter customer's name: ");
stringBalance = JOptionPane.showInputDialog("Enter customer's balance: ");
// Convert to double.
balance = Double.parseDouble(stringBalance);
System.out.println(customerName + "\n");
interest = 0.0; // Start out with 0.0 value for the customer.
payment = 0.0; // Start out with 0.0 value for the customer.
// Write your while loop here.
while (balance > sentinel)
{
// Write your loop body calculations here.
balance = balance + (balance * .013);
payment = balance - (balance +.004);
System.out.println("Payment: " + payment);
System.out.println("New Balance: " + balance + "\n");
} // End of while loop.
System.out.println("Account Number: " + accountNumber);
System.out.println("Final Balance Amount: " + balance);
System.out.println("Loan Paid Off");
System.exit(0);
} // End of main() method.
} // End of Payoff class.