我正在使用已经使用多年的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
(
最佳答案
这些方法已在4.6 API中添加到MathUtilities中,因此您需要针对该版本或更高版本进行编译才能使用它们。
如果确实需要针对4.3或4.5进行编译,则需要在其他地方找到这些功能的J2ME实现。