calculation issues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pcbutts1

    #1

    calculation issues

    This is a simple mortgage calculator and it compiles but I am totally
    confused on the calculation to get it to work. Can someone help me a little.



    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event. *;

    public class Cbweek1b {

    double a, t, i, payments;
    JLabel amountLbl, termLbl, IntrateLbl, paymentsLbl;
    JTextField amountTf, termTf, intrateTf, paymentsTf;
    JButton calcBtn;
    JFrame frame;
    Font font;

    public Cbweek1b() {
    System.out.prin tln("Starting Mortgage Calculator GUI.");

    font = new Font("Arial",Fo nt.BOLD,24);

    amountLbl = new JLabel("Loan Amount");
    termLbl = new JLabel("Terms") ;
    IntrateLbl = new JLabel("Interes t Rate");
    paymentsLbl = new JLabel("Monthly amount");


    amountTf = new JTextField();
    termTf = new JTextField();
    intrateTf = new JTextField();
    paymentsTf = new JTextField();

    calcBtn = new JButton("Calcul ate");

    amountLbl.setFo nt(font);
    termLbl.setFont (font);
    IntrateLbl.setF ont(font);
    paymentsLbl.set Font(font);
    amountTf.setFon t(font);
    termTf.setFont( font);
    intrateTf.setFo nt(font);
    paymentsTf.setF ont(font);
    calcBtn.setFont (font);

    frame = new JFrame("Mortgag e Calculator");
    frame.setLayout (new GridLayout(6,6) );
    frame.add(amoun tLbl);
    frame.add(amoun tTf);
    frame.add(termL bl);
    frame.add(termT f);
    frame.add(Intra teLbl);
    frame.add(intra teTf);
    frame.add(payme ntsLbl);
    frame.add(payme ntsTf);
    frame.add(calcB tn);


    frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);

    calcBtn.addActi onListener(new ActionListener( ) {
    public void actionPerformed (ActionEvent e) {
    calculate();
    }
    });

    frame.setLocati on(300, 200);
    // frame.setSize(3 00, 300);
    frame.pack();
    frame.setVisibl e(true);

    }

    public static void main(String[] args) {
    new Cbweek1b();
    }

    private void calculate() {
    double a = Double.parseDou ble(amountTf.ge tText());
    double t = Double.parseDou ble(termTf.getT ext());
    double i = Double.parseDou ble(intrateTf.g etText());
    double payments = a * t;
    paymentsTf.setT ext("" + payments);
    }
    }

    --


    The best live web video on the internet http://www.seedsv.com/webdemo.htm
    NEW Embedded system W/Linux. We now sell DVR cards.
    See it all at http://www.seedsv.com/products.htm
    Sharpvision simply the best http://www.seedsv.com




  • pcbutts1

    #2
    Re: calculation issues

    Update: I have this working but the calculations are wrong. Where is my
    mistake?


    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event. *;

    public class Cbweek1b {

    double a, t, i, payments;
    JLabel amountLbl, termLbl, IntrateLbl, paymentsLbl;
    JTextField amountTf, termTf, intrateTf, paymentsTf;
    JButton calcBtn;
    JFrame frame;
    Font font;

    public Cbweek1b() {
    System.out.prin tln("Starting Mortgage Calculator GUI.");

    font = new Font("Arial",Fo nt.BOLD,24);

    amountLbl = new JLabel("Loan Amount");
    termLbl = new JLabel("Terms") ;
    IntrateLbl = new JLabel("Interes t Rate");
    paymentsLbl = new JLabel("Monthly amount");


    amountTf = new JTextField();
    termTf = new JTextField();
    intrateTf = new JTextField();
    paymentsTf = new JTextField();

    calcBtn = new JButton("Calcul ate");

    amountLbl.setFo nt(font);
    termLbl.setFont (font);
    IntrateLbl.setF ont(font);
    paymentsLbl.set Font(font);
    amountTf.setFon t(font);
    termTf.setFont( font);
    intrateTf.setFo nt(font);
    paymentsTf.setF ont(font);
    calcBtn.setFont (font);

    frame = new JFrame("Mortgag e Calculator");
    frame.setLayout (new GridLayout(6,6) );
    frame.add(amoun tLbl);
    frame.add(amoun tTf);
    frame.add(termL bl);
    frame.add(termT f);
    frame.add(Intra teLbl);
    frame.add(intra teTf);
    frame.add(payme ntsLbl);
    frame.add(payme ntsTf);
    frame.add(calcB tn);


    frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);

    calcBtn.addActi onListener(new ActionListener( ) {
    public void actionPerformed (ActionEvent e) {
    calculate();
    }
    });

    frame.setLocati on(300, 200);
    // frame.setSize(3 00, 300);
    frame.pack();
    frame.setVisibl e(true);

    }

    public static void main(String[] args) {
    new Cbweek1b();
    }

    private void calculate() {
    double a = Double.parseDou ble(amountTf.ge tText());
    double t = Double.parseDou ble(termTf.getT ext());
    double i = Double.parseDou ble(intrateTf.g etText());
    double payments = a * i/ (1.0 - Math.pow(i+1,-t));
    paymentsTf.setT ext("" + payments);
    }
    }

    --


    The best live web video on the internet http://www.seedsv.com/webdemo.htm
    NEW Embedded system W/Linux. We now sell DVR cards.
    See it all at http://www.seedsv.com/products.htm
    Sharpvision simply the best http://www.seedsv.com



    "pcbutts1" <pcbutts1@seeds v.comwrote in message
    news:4dudnZoWAP pYkjrZnZ2dnUVZ_ sOdnZ2d@giganew s.com...
    This is a simple mortgage calculator and it compiles but I am totally
    confused on the calculation to get it to work. Can someone help me a
    little.
    >
    >
    >
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event. *;
    >
    public class Cbweek1b {
    >
    double a, t, i, payments;
    JLabel amountLbl, termLbl, IntrateLbl, paymentsLbl;
    JTextField amountTf, termTf, intrateTf, paymentsTf;
    JButton calcBtn;
    JFrame frame;
    Font font;
    >
    public Cbweek1b() {
    System.out.prin tln("Starting Mortgage Calculator GUI.");
    >
    font = new Font("Arial",Fo nt.BOLD,24);
    >
    amountLbl = new JLabel("Loan Amount");
    termLbl = new JLabel("Terms") ;
    IntrateLbl = new JLabel("Interes t Rate");
    paymentsLbl = new JLabel("Monthly amount");
    >
    >
    amountTf = new JTextField();
    termTf = new JTextField();
    intrateTf = new JTextField();
    paymentsTf = new JTextField();
    >
    calcBtn = new JButton("Calcul ate");
    >
    amountLbl.setFo nt(font);
    termLbl.setFont (font);
    IntrateLbl.setF ont(font);
    paymentsLbl.set Font(font);
    amountTf.setFon t(font);
    termTf.setFont( font);
    intrateTf.setFo nt(font);
    paymentsTf.setF ont(font);
    calcBtn.setFont (font);
    >
    frame = new JFrame("Mortgag e Calculator");
    frame.setLayout (new GridLayout(6,6) );
    frame.add(amoun tLbl);
    frame.add(amoun tTf);
    frame.add(termL bl);
    frame.add(termT f);
    frame.add(Intra teLbl);
    frame.add(intra teTf);
    frame.add(payme ntsLbl);
    frame.add(payme ntsTf);
    frame.add(calcB tn);
    >
    >
    frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
    >
    calcBtn.addActi onListener(new ActionListener( ) {
    public void actionPerformed (ActionEvent e) {
    calculate();
    }
    });
    >
    frame.setLocati on(300, 200);
    // frame.setSize(3 00, 300);
    frame.pack();
    frame.setVisibl e(true);
    >
    }
    >
    public static void main(String[] args) {
    new Cbweek1b();
    }
    >
    private void calculate() {
    double a = Double.parseDou ble(amountTf.ge tText());
    double t = Double.parseDou ble(termTf.getT ext());
    double i = Double.parseDou ble(intrateTf.g etText());
    double payments = a * t;
    paymentsTf.setT ext("" + payments);
    }
    }
    >
    --
    >
    >
    The best live web video on the internet http://www.seedsv.com/webdemo.htm
    NEW Embedded system W/Linux. We now sell DVR cards.
    See it all at http://www.seedsv.com/products.htm
    Sharpvision simply the best http://www.seedsv.com
    >
    >
    >
    >

    Comment

    • Edwin Castro

      #3
      Re: calculation issues

      pcbutts1 wrote:
      Update: I have this working but the calculations are wrong. Where is my
      mistake?
      What is the behavior you see? I assume you can click on the button to
      perform the calculation but the result is incorrect. How is it
      incorrect? What inputs are you using and what output are you getting?

      Comment

      Working...