Need help on this working properly... it outputs a wrong result.. is it just the math operation at the bottom? What should the equation read as? private JButton buttonCalc; public Calculato...
I don't think so. I don't want it to. 12751.16753711824 is definately not a good thing tho. Monthly payment of 12,751 for $350,000 over 30 years on 7 percent interest rate is WAY off to say the ...
What I mean is, you should multiply the term variable by 12 before plugging it into your formula. That 12,000 figure is definitely wrong. It should be around $2300.
Instead of using:
textFieldResult.setText(Double.toString(result));
in the setResultValue method try the following:
DecimalFormat myFormat = new DecimalFormat("#,###,###,##0.00");
StringBuffer myResult = myFormat.format(result, null, null);
testFieldResult.setText(myResult.toString());
I think this should work.
Calculator.java:72: cannot find symbol
symbol : class DecimalFormat
location: class Calculator
DecimalFormat myFormat = new DecimalFormat("#,###,###,##0.00");
^
Calculator.java:72: cannot find symbol
symbol : class DecimalFormat
location: class Calculator
DecimalFormat myFormat = new DecimalFormat("#,###,###,##0.00");
^
Calculator.java:74: cannot find symbol
symbol : variable testFieldResult
location: class Calculator
testFieldResult.setText(myResult.toString());
^
3 errors
You need to import java.text.DecimalFormat. Also, I made a typo. It should be textFieldResult.
Now this happens after the Calculate button is hit :(
Action Button
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.text.DecimalFormat.format(Unknown Source)
at Calculator.setResultValue(Calculator.java:75)
at Calculator.actionPerformed(Calculator.java:85)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Hmm... Looks like I was reading the javadoc wrong. Try this:
DecimalFormat myFormat = new DecimalFormat("#,###,###,##0.00");
textFieldResult.setText(myFormat.format(result));
I even tested this this time, and it worked for me.
Big thanks mate. That did the trick.