Help with While Loop - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with While Loop

ej138ej138 Posts: 1Member
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 + "
");

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");

System.exit(0);
} // End of main() method.

} // End of Payoff class.


Comments

  • EntertiEnterti Posts: 16Member
    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.