473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Look but could not find the answer.

My program seems to slove for all the mortgages at once. And will not clear out the pane and accept another choice by the user. Can someone steer me in the right direction with this problem. My program is shown below!




Expand|Select|Wrap|Line Numbers
  1.  import java.awt.*; 
  2. import javax.swing.*;
  3. import java.math.*;
  4. import java.awt.event.*;
  5. import java.text.*;
  6. import java.lang.*;
  7. import java.util.ArrayList.*;
  8.  
  9.  
  10. public class wk4_jrs extends JFrame implements ActionListener
  11.     {
  12.     public static void main(String[] args)
  13.         {
  14.             wk4_jrs calc = new wk4_jrs();
  15.             }
  16.     //labels and fields
  17.     JLabel amountLabel = new JLabel("Principle Loan");
  18.     JTextField amountField = new JTextField(7);
  19.  
  20.     //array list created
  21.     String[] mortgageArray = {"Select A Loan", "7 years @ 5.35%", "15 Years @ 5.50%", "30 Years @ 5.75%"};
  22.  
  23.     JComboBox mortgageMenu = new JComboBox(mortgageArray);
  24.  
  25.     JButton calculateButton = new JButton("Calculate");
  26.     JButton myButton = new JButton("Clear");
  27.     JButton myButton1 = new JButton("Exit");
  28.  
  29.     JFrame Frame = new JFrame();
  30.     JPanel con = new JPanel();
  31.     JTextArea outputArea = new JTextArea();
  32.  
  33. DecimalFormat decimalPlaces = new DecimalFormat("0.00");
  34.  
  35.     public wk4_jrs()
  36.     {
  37.     //set size of window
  38.     super("Joe's Mortgage Calculator");
  39.     setSize(600,900);
  40.     setVisible(true);
  41.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42.  
  43.  
  44.     FlowLayout layout = new FlowLayout();
  45.     Container pane = getContentPane();
  46.     pane.setLayout(layout);
  47.  
  48.     //pane layout and action listeners
  49.     pane.add(amountLabel);
  50.     pane.add(amountField);
  51.     amountField.requestFocus();
  52.     amountField.addActionListener(this);
  53.     pane.add(mortgageMenu);
  54.     mortgageMenu.addActionListener(this);
  55.     pane.add(calculateButton);
  56.     calculateButton.addActionListener(this);
  57.     pane.add(myButton);
  58.     myButton.addActionListener(this);
  59.     pane.add(myButton1);
  60.     myButton1.addActionListener(this);
  61.  
  62.  
  63.     setContentPane(pane);
  64.     pane.setBackground(Color.red);
  65.  
  66.  
  67.     outputArea = new JTextArea(40,40);
  68.     outputArea.setLineWrap(true);
  69.     outputArea.setWrapStyleWord(true);
  70.     outputArea.setEditable(false);
  71.  
  72.     JScrollPane scroller = new JScrollPane(outputArea,
  73.     ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
  74.     ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
  75.  
  76.     pane.add(scroller);
  77.     setContentPane(pane);
  78.     }
  79.     public void actionPerformed(ActionEvent event)
  80.     {
  81.         //action events    
  82.         Object source = event.getSource();
  83.  
  84.  
  85.     if( source == myButton)
  86.         {
  87.             amountField.setText(null);
  88.             outputArea.setText(null);            
  89.         }
  90.  
  91.     if( source == myButton1)
  92.         {
  93.             System.exit(0);
  94.         }
  95.  
  96.         if( source == calculateButton)
  97.         {
  98.         String amount = amountField.getText();
  99.  
  100.         }        
  101.             //declares variables
  102.  
  103.         double payment1, payment2, payment3;
  104.         double interestmonthly1, interestmonthly2, interestmonthly3;
  105.         double amount1, amount2, amount3;
  106.         double principle1, principle2, principle3;
  107.         char userInput;
  108.         double interest1, interest2, interest3;
  109.  
  110.  
  111.             amount1 = 200000;
  112.             amount2 = 200000;
  113.             amount3 = 200000;
  114.  
  115.             interest1 = 0.0535;
  116.             interest2 = 0.0550;
  117.             interest3 = 0.0575;
  118.  
  119.         //formulas used in program
  120.         payment1 = (amount1*((0.0535/12)/(1-Math.pow((1+(0.0535/12)), -(30*12)))));
  121.         payment2 = (amount2*((0.0550/12)/(1-Math.pow((1+(0.0550/12)), -(15*12)))));
  122.         payment3 = (amount3*((0.0575/12)/(1-Math.pow((1+(0.0575/12)), -(7*12)))));
  123.  
  124.         //sets decimal places
  125.         DecimalFormat decimalPlaces = new DecimalFormat("0.00");
  126.  
  127.  
  128.         //prints information to users
  129.         outputArea.append("Monthly payment loan 1$ "+decimalPlaces.format (payment1));
  130.         outputArea.append("Monthly payment loan 2$ "+decimalPlaces.format (payment2));
  131.      outputArea.append("Monthly payment loan 3$ "+decimalPlaces.format (payment3));                
  132.  
  133.  
  134.         for(int i=1; i<361; i=i+1)
  135.         {
  136.             interestmonthly1=(amount1*(interest1/12));
  137.             principle1=(payment1-interest1);
  138.             amount1=(interestmonthly1+amount1)-payment1;    
  139.  
  140.             interestmonthly2=(amount2*(interest2/12));
  141.             principle2=(payment2-interest2);
  142.             amount2=(interestmonthly2+amount2)-payment2;
  143.  
  144.             interestmonthly3=(amount3*(interest3/12));
  145.             principle3=(payment3-interest3);
  146.             amount3=(interestmonthly3+amount3)-payment3;
  147.  
  148.     //Array statments
  149.         double[] monthlypayment = {(payment1), (payment2), (payment3)};
  150.         double[] interestamount = {(interestmonthly1), (interestmonthly2), (interestmonthly3)};
  151.         double[] principle = {(principle1), (principle2), (principle3)};
  152.         double[] ammount = {(amount1), (amount2), (amount3)};
  153.  
  154.  
  155.          outputArea.append("\nMonthly Payments are: "+i);
  156.  
  157.         //Begin if & else loops
  158.         if(ammount[0]>=0)
  159.         {
  160.             outputArea.append("\nLoan 1 Payments:$"+decimalPlaces.format(monthlypayment[0])+"\tInterest Paid:$"+decimalPlaces.format(interestamount[0])+"\t Principle:$"+decimalPlaces.format(principle[0])+"\tNew Loan Balance:$"+decimalPlaces.format(ammount[0]));
  161.     }
  162.  
  163.             {
  164.     outputArea.append("\nLoan will be paid in full in 360 payments.");
  165.             }
  166.  
  167.         if(ammount[1]>=0)
  168.         {
  169. outputArea.append("\nLoan 2 Payments:$"+decimalPlaces.format(monthlypayment[1])+"\tInterest Paid:$"+decimalPlaces.format(interestamount[1])+"\t Principle:$"+decimalPlaces.format(principle[1])+"\tNew Loan Balance:$"+decimalPlaces.format(ammount[1]));
  170.     }
  171.                 else
  172.             {
  173.     outputArea.append("\nLoan will be paid in full in 180 payments.");
  174.             }
  175.  
  176.         if(ammount[2]>=0)
  177.         {
  178. outputArea.append("\nLoan 3 Payments:$"+decimalPlaces.format(monthlypayment[2])+"\tInterest Paid:$"+decimalPlaces.format(interestamount[2])+"\t Principle:$"+decimalPlaces.format(principle[2])+"\tNew Loan Balance:$"+decimalPlaces.format(ammount[2]));
  179.             }
  180.                 else
  181.             {
  182.     outputArea.append("\nLoan will be paid in full in 84 payments.");
  183.             }
  184.     }
  185.         }
  186.             }
  187.  
Apr 2 '07 #1
0 1135

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.