Help with While Loop

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:

// - 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 + "

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 + "
} // End of while loop.
System.out.println("Account Number: " + accountNumber);
System.out.println("Final Balance Amount: " + balance);
System.out.println("Loan Paid Off");

} // End of main() method.

} // End of Payoff class.


  • okay heres what you had
    balance = balance + (balance * .013);
    payment = balance - (balance +.004);
    this is what it should be based on your parameters
    balance = balance + (balance * .013);
    payment = balance - (balance * .04);
    balance = balance - payment;
    the biggest change is that now the balance isnt increasing more than it is decreasing, you had .004 rather than the .04 specified difference between .4 and 4 percent, also previously you did nothing to decrease the balance with the payment variable so try this if it does not work post that it doesnt and ill try to fix it
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion