Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 11
Registered: ‎09-16-2010
My Device: Blackberry Curve 8330
My Carrier: Telus

MathUtilities.pow & MathUtilities.round compile problems

I'm creating a BlackBerry application from an Excel application that I've used for several years, that calculates mortgage loan details, but I'm having problems with three calculations involving MathUtilities.pow & MathUtilities.round.

 

**The three original Excel calculations giving me problems when I attempt to build them in my BB application are:

 

((1+(air/2)^)^(1/12)-1

round((1+d)^12-1,4)

(a*d)/1-(1+d)^(-c))

 

Here's my app & the compile error messages that are giving me problems. I've also included my original Excel calculations as reference to what I am trying to calculate using MathUtilities.

Would appreciate some guidance to resolve the problems.

 

public class LoginSuccessScreen extends MainScreen implements FieldChangeListener {

double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;

 

EditField mortamt;

EditField air;

NumericChoiceField amort;

NumericChoiceField term;

ObjectChoiceField freq;

ButtonField calcButton = null;

 

public LoginSuccessScreen(String username) {

add(new LabelField("Logged in!"));

add(new LabelField("Username: " + username));

 

add(new SeparatorField());

 

TextFilter numeric = new NumericTextFilter(NumericTextFilter.ALLOW_DECIMAL);

 

mortamt = new EditField("", "");

LabelField mortamtLabel = new LabelField("Mortgage Amount: $ ", Field.FIELD_LEFT);

air = new EditField("", "");

air.setFilter(numeric);

LabelField airLabel = new LabelField("Annual Interest Rate:% ", Field.FIELD_LEFT);

amort = new NumericChoiceField("",1,35,1,19);

LabelField amortLabel = new LabelField("AmortizationSmiley SadYears)", Field.FIELD_LEFT);

term = new NumericChoiceField("",1,35,1,19);

LabelField termLabel = new LabelField("Mortgage Term: (Years)", Field.FIELD_LEFT);

freq= new ObjectChoiceField("", new String[] {"Weekly", "Bi-Weekly","Semi-Monthly", "Monthly"});

LabelField freqLabel = new LabelField("Payment Frequency:", Field.FIELD_LEFT);

 

 

add(new SeparatorField());

 

add(new SeparatorField());

GridFieldManager gridFieldManager = new GridFieldManager(2, 0);

gridFieldManager.add(mortamtLabel);

gridFieldManager.add(mortamt);

gridFieldManager.add(airLabel);

gridFieldManager.add(air);

gridFieldManager.add(amortLabel);

gridFieldManager.add(amort);

gridFieldManager.add(termLabel);

gridFieldManager.add(term);

gridFieldManager.add(freqLabel);

gridFieldManager.add(freq);

 

add(gridFieldManager);

 

calcButton = new ButtonField("Calculate Amounts:", ButtonField.CONSUME_CLICK);

calcButton.setChangeListener(this);

add(calcButton);

 

}

public void fieldChanged(Field field, int context) {

if (calcButton == field) {

}

 

int a = Integer.parseInt(mortamt.getText());

add(new LabelField("Principal Amount: $" + a));

 

int b = Integer.parseInt(amort.getChoice(amort.getSelectedIndex()).toString());

add(new LabelField("Period to Amortization " +b * 12 + " months"));

 

double c = Float.parseFloat(air.getText()) / 100.;

add(new LabelField("AIR: %" + c));

 

add(new LabelField("Monthly Interest Factor %" + d));

double d = MathUtilities.pow(MathUtilities.pow((1+(c/2)), 2), 1/12) - 1;

 

add(new LabelField("EAR: " +e ));

double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;

 

add(new LabelField("Monthly Payment: $" + f));

double f = ((a*d)/(MathUtilities.pow(1-(1+d)) -c));

 

add(new SeparatorField());

}

}

**ERROR MESSAGES:**

C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:102: cannot find symbol

symbol : method pow(double,int)

location: class net.rim.device.api.util.MathUtilities

double d = MathUtilities.pow(MathUtilities.pow((1+(c/2)), 2), 1/12) - 1;

^

C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:105: cannot find symbol

symbol : method pow(double,int)

location: class net.rim.device.api.util.MathUtilities

double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;

^

C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:105: cannot find symbol

symbol : method round(int)

location: class net.rim.device.api.util.MathUtilities

double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;

^

C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:105: inconvertible types

found : net.rim.device.api.util.MathUtilities.round

required: float

double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;

^

C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:108: cannot find symbol

symbol : method pow(double)

location: class net.rim.device.api.util.MathUtilities

double f = ((a*d)/(MathUtilities.pow(1-(1+d)) -c));

^

5 errors

Error!: Error: java compiler failed: javac -source 1.3 -target 1.1 -g -O -d C:\Users\ALEXMC~1\AppData\Local\Temp\rapc_1c2f4822.dir -boot ...

Error while building project

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: MathUtilities.pow & MathUtilities.round compile problems

[ Edited ]

A quick check of the javadocs explains the issue.

 

public static double pow(double x,
                         double y)

 

MathUtilities.pow() requires two parameters, and they are both doubles.

 

So, this is wrong:

 

pow(5.0, 2)

 

...you will get an error because the 2nd parameter is an integer (by default)

 

this will work:

 

pow(5.0,2.0)

 

Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: MathUtilities.pow & MathUtilities.round compile problems

What are you talking about @Rex? The Java compiler implicitly converts an integer to a double, you won't get an error from that.

 

What API are you using? MathUtilities.pow and round were not introduced until 4.6, if you are using 4.6 or higher then can you post the error messages you are getting?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Contributor
Posts: 11
Registered: ‎09-16-2010
My Device: Blackberry Curve 8330
My Carrier: Telus

Re: MathUtilities.pow & MathUtilities.round compile problems

Thanks for your response....

Unfortunately my BB software version is only 4.5.0.186.   Is there any coding I can apply to enable my appication to function on my BlackBerry?


Appreciate any guidance you can offer.

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: MathUtilities.pow & MathUtilities.round compile problems

Implement your own POW and Round methods for pre 4.6 devices, it's pretty rudimentary algebra.

Contributor
Posts: 11
Registered: ‎09-16-2010
My Device: Blackberry Curve 8330
My Carrier: Telus

Re: MathUtilities.pow & MathUtilities.round compile problems

Smiley HappyThanks....Will give it a try.

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: MathUtilities.pow & MathUtilities.round compile problems

I was going to say to do some searching because there are other people who have had this issue but I ended up having issues myself so here:

http://supportforums.blackberry.com/t5/Java-Development/MathUtilities-alternatives-to-pow-acos-asin-...

 

When I have had issues like this I use some of the stuff from this, mainly J4ME (on second page).

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Contributor
Posts: 11
Registered: ‎09-16-2010
My Device: Blackberry Curve 8330
My Carrier: Telus

Re: MathUtilities.pow & MathUtilities.round compile problems

Thanks....Much appreciated!!