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

