Help editting code

Hi, im trying to make a program for my computer science class. And i wrote the whole thing, but i just need to know how to make it loops on a few things. Here are the specifications so you understand what my program is doing.

I am making this for an imaginary store's credit plan

-There is a 10 percent down payment

-Annual interest rate of 12 percent

-Monthly payments are 5 percent of the purchase price minus the down payment

It outputs in a table:

-Month number

-Current total balance owed

-The interest owed for that month

-The amount of principal owed for that month

-The payment for that month

-The balance at the end of the month

-Interest per month is equal tobalance * rate / 12

-principal per month is equal to5 percent of the purchase price minus the down payment

So i have written this, and when i enter in a number and press enter, i only get one line in the table. I want it to print out many lines that keep on repeating until the person fully pays off the credit. Then, i need the month number to increase by one on each line. I hope you guys understand. Here is the code:

import javax.swing.*;

import BreezySwing.*;

publicclass Project76extends GBFrame{

//Declare variables for the window objects

private JLabelpriceLabel;

private DoubleField priceField;

private JButton enterButton;

private JTextAreaoutput;

//Define other instance variables

privatedouble month;//The month number

privatedouble totalBalanceOwed;//The current total balance owed

privatedoubleinterestOwed;//The interest owed for that month

privatedouble principalOwed;//The principal owed for the month

privatedouble monthlyPayment;//The payment for that month

privatedouble balance;//The balance remaining after payment

//Constructor

public Project76 (){

//Define the table's header line

String header = Format.justify('l',"Month", 10) +

Format.justify('l',"Current Balance Owed", 24) +

Format.justify('l',"Interest Owed This Month", 28) +

Format.justify('l',"Principal Owed This Month", 29) +

Format.justify('l',"Month's Payment", 19) +

Format.justify('l',"Balance", 7) +"\n";

//Instantiate the window objects

priceLabel = addLabel ("Purchase Price" ,1,1,1,1);

priceField = addDoubleField (0 ,1,2,1,1);

enterButton = addButton ("Enter" ,2,1,1,1);

output = addTextArea (header ,3,1,5,6);

//Disable the text area because that is the output, we do not want

//the user to try to change the output.

//Set the focus to input (purchase price)

output.setEnabled(false);

priceField.requestFocus();

//Initialize the values to zero

month = 0;

totalBalanceOwed = 0;

interestOwed = 0;

principalOwed = 0;

monthlyPayment = 0;

balance = 0;

}

//Respond to the command buttons

publicvoid buttonClicked (JButton buttonObj){

if (buttonObj == enterButton){

processInput();

priceField.requestFocus();

}else{

enterButton.setEnabled(false);//Prevent the user from trying to

//computer when there is no input

}

}

//Read the inputs, compute the values, format and display the outputs

privatevoid processInput(){

//Declare local variables

double price;//The price of the loan

double month;//The month number

double totalBalanceOwed;//The current total balance owed

doubleinterestOwed;//The interest owed for that month

double principalOwed;//The principal owed for the month

double monthlyPayment;//The payment for that month

double balance;//The balance remaining after payment

//Read user input

price = priceField.getNumber();

//Calculate the outputs

totalBalanceOwed = price - (price*.10);

interestOwed = totalBalanceOwed*.12/12;

principalOwed = totalBalanceOwed*.05;

monthlyPayment = interestOwed + principalOwed;

balance = totalBalanceOwed - monthlyPayment;

month = 1;

//Display the outputs

displayNumbers (month, totalBalanceOwed, interestOwed, principalOwed,

monthlyPayment, balance);

}

//Format another line and append to text area

privatevoid displayNumbers (double month,double totalBalanceOwed,double interestOwed,

double principalOwed,double monthlyPayment,double balance){

String numberLine = Format.justify('l', month, 5, 2) +

Format.justify('l', totalBalanceOwed, 20, 2) +

Format.justify('l', interestOwed, 24, 2) +

Format.justify('l', principalOwed, 25 ,2) +

Format.justify('l', monthlyPayment, 15 ,2) +

Format.justify('l', balance, 7, 2);

output.append (numberLine +"\n");

}

publicstaticvoid main (String [] args){

Project76 theGUI =new Project76();

theGUI.setSize (800, 600);

theGUI.setVisible(true);

}

}

[8671 byte] By [hugged2deatha] at [2007-10-2 13:44:55]
# 1
Have a look at the [url= http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html]Control Flow[/url] section of the Java Tutorial, especially the loop part
andiha at 2007-7-13 11:41:39 > top of Java-index,Java Essentials,Java Programming...
# 2
maybe i should clarify my question now, where should i put these loops? and how would i do the thing with the months too?
hugged2deatha at 2007-7-13 11:41:39 > top of Java-index,Java Essentials,Java Programming...
# 3

> maybe i should clarify my question now, where should i put these loops? and how would i do the thing with the months too?

Hint: You have a position within your code that calls a method which formats the output and which you pass the month. This method is currently called exactly one time. At this line there is allso a commen "//Display the outputs".

Try it and if you have trouble you can come back.

andiha at 2007-7-13 11:41:39 > top of Java-index,Java Essentials,Java Programming...
# 4

i tried to put a for loop, then a while loop, but i couldnt get them to work. I dont think i am doing it right. Can you please just tell me what code i should use to make it loop? I dont know if im being whiny...but i just started java a few months ago, and i have been working on this code for about 3 hours (yes, i know im slow...) and right now im getting really frustrated.

please...?

hugged2deatha at 2007-7-13 11:41:39 > top of Java-index,Java Essentials,Java Programming...
# 5
Post what you've tried and we'll have a look at it.Please post only the part of the loop not the whole code and use the code tags.
andiha at 2007-7-13 11:41:39 > top of Java-index,Java Essentials,Java Programming...
# 6

okay, its been a few days that ive put off doing this code. But now im back at it. To answer the last post, here is somethings i have tried. for (month = 1; month <=19; month++)

balance = totalBalanceOwed;

displayNumbers (month, totalBalanceOwed, interestOwed, principalOwed,

monthlyPayment, balance);

while (month <= 20){

displayNumbers (month, totalBalanceOwed, interestOwed, principalOwed,

monthlyPayment, balance);

month++;

balance = totalBalanceOwed;

}

i dont know how to fix this. Can someone answer my question directly?

hugged2deatha at 2007-7-13 11:41:39 > top of Java-index,Java Essentials,Java Programming...
# 7
by the way, i got the month increment problem fixed. I just need the numbers to change along with the months now...
hugged2deatha at 2007-7-13 11:41:39 > top of Java-index,Java Essentials,Java Programming...