help please ( the right assignment this time)

You are gonna be really pissed at me but I need to tell you this

The help I asked you for was for the wrong assignment.

the assignment. all that brain power went to waist.

the correct assignment that I need to complete by tongite is

this. I have to take my last weeks project ( which works just fine)

and modify the output.

as it sits if you inter the required information it will return the requested

information (a mortgage payment)

Now when you input the requestied information. the output needs to be

a complete amortization schedule and no longer the simple monthly payment.

I totally appogize for waisting your time with my last request. I should pay more attention in the future.

I will still give the duke dollars for my "bogas" request becuase it is the right thing to do.

I will also post this under its own thread so I make the offer here as well.

below is the code

/**

* This program will compute the monthly mortgage payment

* amount, given the user input of:

* Total Mortgage Amount borrowed

* The Length of the mortgage in years

* The yearly interest rate of the mortage

*

* The user can compute as many computations as he/she wishes

* and need just close the window to terminate the program.

*

* NOTE: There is currently no checking/handling of incorrect input, as in,

* no numbers entered, negative numbers, leters, etc.

*

*/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.text.*;

import java.util.*;

publicclass ComputePayment2extends JFrameimplements ActionListener

{

publicstaticfinalint NUMBER_OF_FINANCE_OPTIONS = 3;

JFrame paymentFrame;

JPanel mortgagePanel, checkBoxPanel, resultPanel, emptyPanel;

JTextField mortAmount, intRate, mortLength;

JLabel mortAmountLabel, paymentLabel, rateLabel, lengthLabel, emptyString;

JButton computePaymentButton, clearButton;

JCheckBox checkBox[] =new JCheckBox[NUMBER_OF_FINANCE_OPTIONS];

DecimalFormat decimalFormat =new DecimalFormat("$###,###.##");

boolean selectedOption[] =newboolean[NUMBER_OF_FINANCE_OPTIONS];

boolean hasNotBeenPrinted =true;

JTextArea textArea;

String yearRate[] ={"7 Years at 5.35%","15 Years at 5.5%","30 Years at 5.75%"};

String totalYears[] ={"After 7 Years","After 15 Years","After 30 Years"};

public ComputePayment2()

{

//Create and set up the window.

paymentFrame =new JFrame("Compute Monthly Mortgage Payment");

paymentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

paymentFrame.setSize(500, 500);

Container contentPane = getContentPane();

//Set layout with 3 rows and 1 column

contentPane.setLayout(new GridLayout(4,1));

/*** First Cell ***/

// Create and set up the mortgage panel that accepts user entry.

mortgagePanel =new JPanel(new GridLayout(1, 3));

mortAmount =new JTextField(10);

mortAmountLabel =new JLabel("Enter Mortgage Amount: ", SwingConstants.RIGHT);

mortAmountLabel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));

// Add these to their panel and the main pane

mortgagePanel.add(mortAmountLabel);

mortgagePanel.add(mortAmount);

// just used for helping placement of the elements in this panel

emptyString =new JLabel("");

mortgagePanel.add(emptyString);

/*** Cells 2-4 ***/

// Contains the check boxes for each finance option

checkBoxPanel =new JPanel(new GridLayout(4, 1));

JLabel label =new JLabel("Select the year(s) and interest rate(s) you would like to finance at:");

checkBoxPanel.add(label);

//Make a check box for each mortage length/interest rate option

for(int index = 0; index < yearRate.length; index++)

{

checkBox[index] =new JCheckBox( yearRate[index] ) ;

checkBox[index].addActionListener(this);

//Set default state to unchecked

checkBox[index].setSelected(false);

checkBoxPanel.add( checkBox[index] );

}

// Add the panel to the main pane

contentPane.add( checkBoxPanel );

/*** Last Cell ***/

// Contains the results

resultPanel =new JPanel(new FlowLayout());

// Create a text area to display the results

textArea =new JTextArea(20, 60);

// user can't edit this area

textArea.setEditable(false);

// Make it scrollable, should we need it

JScrollPane textScrollPane =

new JScrollPane( textArea,

JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,

JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

resultPanel.add(textScrollPane);

//Add the compute and clear buttons

JPanel buttonPanel =new JPanel();

buttonPanel.setLayout(new FlowLayout());

computePaymentButton =new JButton("Compute Payment");

clearButton =new JButton("Clear");

// Listen to events for the buttons

computePaymentButton.addActionListener(this);

clearButton.addActionListener(this);

buttonPanel.add(computePaymentButton);

buttonPanel.add(clearButton);

// add the buttons to the resultPanel

resultPanel.add(buttonPanel);

// add result panel to the main pane

contentPane.add(resultPanel);

//Set the default button.

paymentFrame.getRootPane().setDefaultButton(computePaymentButton);

//Add the panels to the window.

paymentFrame.getContentPane().add(mortgagePanel, BorderLayout.NORTH);

paymentFrame.getContentPane().add(checkBoxPanel, BorderLayout.CENTER);

paymentFrame.getContentPane().add(resultPanel, BorderLayout.SOUTH);

//Display the window.

paymentFrame.pack();

paymentFrame.setVisible(true);

}

/**

* Perform an action based on which button was pressed

*/

publicvoid actionPerformed(ActionEvent event)

{

Object source = event.getSource();

if ( source == computePaymentButton )

{

getPaymentInfo();

}

elseif( source == clearButton )

{

// Clear out all the fields for a fresh start

mortAmount.setText("");

textArea.replaceRange("", 0, textArea.getText().length());

//Do the check boxes as well

for(int index = 0; index < NUMBER_OF_FINANCE_OPTIONS; index++)

{

checkBox[index].setSelected(false);

}

}

}

/**

* Get the payment info from the GUI and then compute/display the results

*/

publicvoid getPaymentInfo( )

{

double mortgageAmount;

double mortgageTerm[] ={7.0, 16, 30};// years

double interestRate[] ={.0535, .055, .0575};//int rate / 100.

for(int index = 0; index < NUMBER_OF_FINANCE_OPTIONS; index++ )

{

mortgageAmount = Double.parseDouble(mortAmount.getText());

if( checkBox[index].isSelected() )

{

computePayment(index, mortgageAmount, mortgageTerm[index], interestRate[index]);

}

}

}

/**

* Finally, acutally compute and display the info based on the user input

*/

publicvoid computePayment(int checkBoxID,double mortgageAmount,double mortgageTerm,double interestRate)

{

double monthlyPayment;

double totalLoanPayment;

double totalInterestPaid;

double totalPrincipalPaid;

double loanBalance;

//Only print this once

if( hasNotBeenPrinted )

{

textArea.append("Computed Results:\n");

hasNotBeenPrinted =false;

}

for(int index = 0; index < NUMBER_OF_FINANCE_OPTIONS; index++ )

{

if( index == checkBoxID )

{

//Break the formula into a couple variables for easier reading

double temp1 = mortgageAmount * Math.pow( (1 + interestRate/12), (mortgageTerm* 12 )) * interestRate/12;

double temp2 = Math.pow( (1 + interestRate/12), (mortgageTerm * 12) ) - 1;

// Display the payment amount

monthlyPayment = temp1/temp2;

textArea.append(yearRate[index] +"\t Monthly Payment: " + decimalFormat.format(monthlyPayment) +"\n");

/* Compute some variables over the entire length of the loan */

// Compute the total amount the person will pay over the term

// of the loan, which is the monthly payment times the

// number of months payments will be made

totalLoanPayment = monthlyPayment * (mortgageTerm * 12);

// Compute the total amount of interest that will be paid

// Which is the total amount paid on the loan (above)

// minus the orignial loan amount

totalInterestPaid = totalLoanPayment - mortgageAmount;

// Compute the princial paid

// Principal paid, is just the total amount of the original

// borrowed amount

totalPrincipalPaid = mortgageAmount;

// Compute loan balance, it is assumed, that we

// are showing the user what the total loan would cost, and

// not what the balance would be if the user actually paid it

// off

// At the end of term of the loan, the

loanBalance = totalLoanPayment;

// Display the computed variables

textArea.append(totalYears[index] +"\t Loan Balance: " + decimalFormat.format(loanBalance) +"\n");

textArea.append("\t\t Principal Paid : " + decimalFormat.format(totalPrincipalPaid) +"\n");

textArea.append("\t\t Interest Paid : " + decimalFormat.format(totalInterestPaid) +"\n\n");

// In the future the results will be displayed on individual tabs

// for easier viewing.

// Set up some prototype for use later

//displayTab();

}

}

}

/**

* The function that will add tabs to display the computed variables

* on individual tabs

*/

publicvoid displayTab()

{

// For each arugment that will be passed here a new tab will

// be created

// Basically, tabs are added onto exisitng panels as in:

// First specifying the location of the tab on the panel

int tabLocation = JTabbedPane.TOP;

// Creating the tab itself:

JTabbedPane tabPane =new JTabbedPane();

// Then adding the tab to the panel we already have

// with some sort of label on the tab, so we know what data

// is on it:

String tabLabel ="This is tab1";

tabPane.addTab( tabLabel, resultPanel );

}

// The main program, which gets everything going

publicstaticvoid main(String[] args)

{

ComputePayment2 computePayment =new ComputePayment2();

}

}

[17302 byte] By [rdsii640a] at [2007-10-2 0:14:56]
# 1
and what have you tried, or where are you stuck?
dmbdmba at 2007-7-15 16:16:29 > top of Java-index,Java Essentials,Java Programming...
# 2

basically I have some example code for the formula because in my first java

class I had to write the same program with out a GUI. unless I am totally in the dark I think all I need to do is change the output. The stickler is I don't what lines

I need to change.

and finally do I need to use a different formula to print the amortization for this or just make some changes to the existing formula.

once I figure this part out I think I can handle it.

Not that that I am greatest programmer anyway, but working with gui's are a real weak point for me.

rdsii640a at 2007-7-15 16:16:29 > top of Java-index,Java Essentials,Java Programming...
# 3

> and finally do I need to use a different formula to

> print the amortization for this or just make some

> changes to the existing formula.

> once I figure this part out I think I can handle it.

> Not that that I am greatest programmer anyway, but

> working with gui's are a real weak point for me.

A word of advice then? You should leave out the UI altogether. You should write an object that will produce the amortization table as text, without any Swing UI. Once you have that working, then worry about Swing.

Not only will this play away from your "weak point", but you'll have better design. The calculation shouldn't know or care what the UI is.

%

duffymoa at 2007-7-15 16:16:29 > top of Java-index,Java Essentials,Java Programming...
# 4

If I just write a loop counter to "keep making payments" and output the result to the text area. I won't have to muck around with already working code. This will ad the amortization feature unstead replacing the simple payment output with the amortization out put.

I just don't know where in my code to put it.

rdsii640a at 2007-7-15 16:16:29 > top of Java-index,Java Essentials,Java Programming...
# 5

> If I just write a loop counter to "keep making

> payments" and output the result to the text area. I

> won't have to muck around with already working code.

> This will ad the amortization feature unstead

> replacing the simple payment output with the

> amortization out put.

>

> I just don't know where in my code to put it.

Don't put it in that messy code. Start from scratch. Throw that mess away. It's getting in the way of progress.

It might be pointing to a problem in your design: if the actual calculations were isolated in a single method, it'd be much clearer where it would go. (I haven't looked at your code hard enough to see if that's true or not; that's your job.)

%

duffymoa at 2007-7-15 16:16:29 > top of Java-index,Java Essentials,Java Programming...