Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 20th, 2005, 4:27 PM   #1
rockybalboa
Newbie
 
Join Date: Mar 2005
Posts: 1
Rep Power: 0 rockybalboa is on a distinguished road
Can't get loop to work

Hello,
Can anyone advise me on why I can't get the following code to loop? I'm trying to get continuous calculation until the variable amount = 0.
I will work out display params after I get the loop to work. I'm new to Java, but not coding. This is a simple program so there's probably a simple answer.
My thanks to anyone willing to teach me.
Thanks
DW

import java.text.*;

class Wk3
{
    public static void main (String[] arguments)    //create main
    {
        int term = 30;                              //init var for length of loan
        double amount = 200000;                        //init var for loan amt
        double pmt = 0;                             //init var for payment
        double rate = .0575;                        //init var for interest rate
        double rateMo = 0;                          //init var for monthly interest paid        
        {
            rate = (rate/12);                       //divide annual rate to get monthly rate
            term = (term * 12);                     //multiply years to get length in months            
            pmt= (amount * (rate)) / (1-Math.pow(1 + rate, - term));    //compute payment
            {
                if (amount > 0)                         //run if counter >0
                {
                    java.text.DecimalFormat dec = new java.text.DecimalFormat(",###.00");               //format next output to dollars.cents
                    System.out.println("\nThis months payment is $" + dec.format (pmt));                //display payment
                    System.out.println ("\nYour loan balance is $" + dec.format (amount));              //display loan amt
                    System.out.println("\nThis months interest is $" + dec.format (amount * (rate )));  //montly interest payment
                }
                amount -=  pmt;
            }
        }
    }
}
rockybalboa is offline   Reply With Quote
Old Mar 20th, 2005, 4:43 PM   #2
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 148
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
its not looping becuase your not using any of the looping structrues in java. there needs to be a while or for or somthing in there to make it loop
ZenMasterJG is offline   Reply With Quote
Old Mar 20th, 2005, 5:06 PM   #3
Pimp Daddy
Programmer
 
Join Date: Aug 2004
Location: Wherever the beautiful women are.
Posts: 30
Rep Power: 0 Pimp Daddy is on a distinguished road
Send a message via MSN to Pimp Daddy Send a message via Skype™ to Pimp Daddy
Quote:
Originally Posted by ZenMasterJG
its not looping becuase your not using any of the looping structrues in java. there needs to be a while or for or somthing in there to make it loop
That's correct - I would recommend using a for loop for this problem.
__________________
David Morris BSc.(Hons), MBCS
Qualified Computer Engineer
Administrator (SEED Software)
Pimp Daddy is offline   Reply With Quote
Old Mar 20th, 2005, 6:19 PM   #4
You Like Java?
Newbie
 
You Like Java?'s Avatar
 
Join Date: Mar 2005
Location: aboho.com (sn:eyvind)
Posts: 20
Rep Power: 0 You Like Java? is on a distinguished road
Send a message via AIM to You Like Java? Send a message via MSN to You Like Java? Send a message via Yahoo to You Like Java?
Is this what you wanted?

import java.text.*;
 
class Wk3
{
	 public static void main (String[] arguments) //create main
	 {
		 int term = 30; //init var for length of loan
		 double amount = 200000; //init var for loan amt
		 double pmt = 0; //init var for payment
		 double rate = .0575; //init var for interest rate
		 double rateMo = 0; //init var for monthly interest paid 
		 while (amount > 0)
		 {
			 rate = (rate/12); //divide annual rate to get monthly rate
			 term = (term * 12); //multiply years to get length in months 
			 pmt= (amount * (rate)) / (1-Math.pow(1 + rate, - term)); //compute payment
			 java.text.DecimalFormat dec = new java.text.DecimalFormat(",###.00"); //format next output to dollars.cents
			 System.out.println("\nThis months payment is $" + dec.format (pmt)); //display payment
			 System.out.println ("\nYour loan balance is $" + dec.format (amount)); //display loan amt
			 System.out.println("\nThis months interest is $" + dec.format (amount * (rate ))); //montly interest payment
			 amount -= pmt;
		 }
	 }
}

(Damn vB formatting...)
__________________
If you need help with Java, you can go to javaforum.tk and get answers quickly.

Programmer YouLikeJava = new JavaProgrammer("Eyvind");
YouLikeJava.printInfo();
YouLikeJava.setWeb("You Like Java?");

Last edited by You Like Java?; Mar 20th, 2005 at 6:22 PM.
You Like Java? is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:24 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC