BlackBerry Math Utilities(Pow& Round)

时间:2010-10-16 12:24:22

标签: java blackberry blackberry-jde

我正在使用我已经使用了几年的Excel应用程序创建一个应用程序来计算抵押贷款的详细信息,但是我遇到了涉及MathUtilities.pow&的三个计算的问题。 MathUtilities.round。

这是我的应用程序&编译错误消息给我带来了问题。我还包括我原来的Excel计算作为我尝试使用MathUtilities计算的参考。

希望得到一些解决问题的指导。

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.util.MathUtilities;
import net.rim.device.api.ui.text.NumericTextFilter;
import net.rim.device.api.ui.text.TextFilter;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.component.NumericChoiceField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.component.ButtonField;;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;

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("Amortization:(Years)", 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());   
             }   
            }

错误信息:

Building UiFun
C:\Research In Motion\BlackBerry JDE 4.5.0\bin\rapc.exe  -quiet import="..\Research In Motion\BlackBerry JDE 4.5.0\lib\net_rim_api.jar" codename=UiFun UiFun.rapc warnkey=0x52424200;0x52525400;0x52435200 "C:\Mortgage Calculator\res\apress_logo.png" "C:\Mortgage Calculator\res\login_arrow.png" "C:\Mortgage Calculator\res\login_icon.png" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomButtonField.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomDialog.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomLabelField.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomObjectChoiceField.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\GridFieldManager.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\UiFunApplication.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\UiFunMainScreen.java"
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

原始的Excel计算是:

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

(

1 个答案:

答案 0 :(得分:1)

这些方法已添加到4.6 API中的MathUtilities中,因此您需要为该版本或更高版本进行编译才能使用它们。

如果你确实需要编译4.3或4.5,你需要在其他地方找到这些函数的J2ME实现。