Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with While Loop Posted by ej138 on 15 Apr 2009 at 6:13 PM
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.


Report
Re: Help with While Loop Posted by Enterti on 16 Apr 2009 at 5:30 PM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.