0

Need help rounding. MoPay.setText is showing up as .########### (I'm new to this language.) Oh, and my dollar sign isn't showing up, does anyone no why?

public void actionPerformed(ActionEvent e)
{
int Mort;
double Int;
int T;


if(e.getSource()==Reset)
{
answer.setText("");
answera.setText("");
answerb.setText("");
MoPay.setText("");
}


else if(e.getSource()==Calculate)
{
try {
Mort = Integer.parseInt(answer.getText());
Int = Double.parseDouble(answera.getText());
T = Integer.parseInt(answerb.getText());
MoPay.setText("$" + (Int - (Mort * Int * T)) / (T*12));


}
catch(java.lang.NumberFormatException NFE)
{
Mort = 0;
Int = 0;
T = 0;
}
}
}

Edited by happygeek: fixed formatting

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by jwenting
0

If I were you I'd start with using proper Java naming conventions, so variable and method names using CamelCase and starting with a lowercase letter, class and interface names similar but starting with an uppercase letter.
Also use meaningful names for your variables and members to make it easier to comprehend what's going on.

What is "Calculate", what is "Reset", etc. etc.?
Are you sure you're intending to use a comparison of the reference values there rather than a comparison of content?
Are you sure that your math is correct? Isn't there an implicit cast somewhere which is causing you to loose precision?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.