- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%
Use an array for the mortgage data for the different loans. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program.
Here is my code but I keep getting an error message
gui.java uses or overrides a deprecated API.
Note:Recompile with -Xlint:deprecation for details
import java.awt.*;
import java.io.*;
import java.text.*;
import java.awt.event.*;
import javax.swing.*;
import static java.lang.Math.pow;
import java.text.DecimalFormat;
import javax.swing.JTextField;
import javax.swing.border.*;
import javax.swing.JOptionPane;
import java.io.IOException;
public class gui extends JFrame implements ActionListener
{
//Create Frame regions.
JPanel jp = new JPanel();
JFrame frame;
JLabel lLoan,lAmt,lLen;
JTextField tLoan,tAmt;
JButton bSubmit,bReset,bExit;
JComboBox duration;
Container container;
public void init()
{
initComponent();
}
private void initComponent()
{
//Create a new JFrane container.
frame = new JFrame(" EZ Loan Company");
container = frame.getContentPane();
//Create the layout
GridBagLayout gbl = new GridBagLayout();
//Set layout on container and Handle buttons
container.setLayout(gbl);
//Place a component at cell location (1,1)
GridBagConstraints gbc = new GridBagConstraints();
String[] lenloan = { "7 Years", "15 Years", "30 Years"};
lLoan= new JLabel("Enter loan Amount");
lAmt = new JLabel("A Mortgage Payment in the amount of "); //output in red
lLen= new JLabel("Length of loan ");
tLoan= new JTextField(10);
tAmt = new JTextField(14);
tAmt.disable();
/* testing these fields
final JTextField textfield = new JTextField( "this is a TEST" );
textfield.setBackground( Color.BLACK );
textfield.setForeground( Color.YELLOW );
textfield.setFont( new Font( "Dialog", Font.BOLD, 15 ) );
textfield.setHorizontalAlignment( JTextField.RIGHT );
textfield.setEnabled( true );
textfield.setEditable( true );
*/
duration = new JComboBox(lenloan);
duration.setSelectedIndex(0);
bSubmit= new JButton("Calculate Payment");
bReset= new JButton("Reset");
bExit= new JButton("Exit");
gbc.gridx = 0;
gbc.gridy = 0;
frame.add(lLoan,gbc);
gbc.gridx = 1;
gbc.gridy = 0;
frame.add(tLoan,gbc);
gbc.gridx = 0;
gbc.gridy = 1;
frame.add(lLen,gbc);
gbc.gridx = 1;
gbc.gridy = 1;
frame.add(duration,gbc);
gbc.gridx = 0;
gbc.gridy = 2;
frame.add(lAmt,gbc);
gbc.gridx = 1;
gbc.gridy = 2;
frame.add(tAmt,gbc);
gbc.gridx = 0;
gbc.gridy = 3;
frame.add(bSubmit,gbc);
bSubmit.addActionListener(this);
gbc.gridx = 1;
gbc.gridy = 3;
frame.add(bReset,gbc);
bReset.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 4;
frame.add(bExit,gbc);
bExit.addActionListener(this);
//Show the frame
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==bSubmit)
{
System.out.println(duration.getSelectedIndex());
gui();
}
else if (e.getSource()==bReset)
{
tLoan.setText("");
duration.setSelectedIndex(0);
tAmt.setText("");
}
else if (e.getSource()==bExit)
System.exit(1);
}
public void gui()
{
DecimalFormat twodigits = new DecimalFormat("$#,###.00");
System.out.println ("\t Assignment 5");
System.out.println ("\t EZ Loan Company ");
System.out.println ();
//Array for length of loan (Term)
double loan = Double.parseDouble(tLoan.getText());
double interest=.0535;
double InterestRate=5.35;
double lengthTerm=7;
if(duration.getSelectedIndex()==0)
{
interest=.0535;
InterestRate=5.35;
lengthTerm=7;
}
else if(duration.getSelectedIndex()==1)
{
interest=.0550;
InterestRate=5.50;
lengthTerm=15;
}
else if(duration.getSelectedIndex()==2)
{
interest=.0575;
InterestRate=5.75;
lengthTerm=30;
}
double payment = (loan*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(lengthTerm*12))));
String ab=""+twodigits.format(payment);
tAmt.setText(ab);
}
}

New Topic/Question
Reply




MultiQuote







|