Skip to main content
0 online
theremin May 8, 2006

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...

iwz May 8, 2006

Try dividing the rate by 1200 instead of 100

dgiaimo May 8, 2006

Shouldn't the term be expressed in months as well, rather than years?

theremin May 8, 2006

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 ...

dgiaimo May 8, 2006

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.

theremin May 9, 2006

If the mentioned changes are applied to now read as: double term = Integer.parseInt(textFieldTerm.getText()) r[/ 12]r; double rate = Double.parseDouble(textFieldRate.getText()) / r[1200]r; dou...

dgiaimo May 9, 2006

It should be: double term = Integer.parseInt(textFieldTerm.getText()) r[*]r 12;

theremin May 10, 2006

I tried get the output of the result to show just two numbers after the decimal, but can't get it to. What do I have to do?

D
dgiaimoOG 2003

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.

theremin thereminOG 2002

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

D
dgiaimoOG 2003

You need to import java.text.DecimalFormat. Also, I made a typo. It should be textFieldResult.

theremin thereminOG 2002

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)

D
dgiaimoOG 2003

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.

theremin thereminOG 2002

Big thanks mate. That did the trick.

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.