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

