BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-30-2010, 09:36 AM   #1 (permalink)
New Member
 
Join Date: Sep 2010
Location: Canada
Model: 8330
PIN: N/A
Carrier: Telus
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems compiling application. Need assistance to understand what I am doing wrong.

Please Login to Remove!

I am trying to create a BB application that will generate a monthly payment table similar to the one that I am currently using in MS Excel. (copy of Excel Table is attached).

Here’s what I have created so far, and I would really appreciate it if you could show me what I am doing wrong. I want to have the application calculate and show the monthly payment amount automatically once the annual interest rate is inserted, and without the use of any button. I am having difficulty compiling the appication.

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.text.TextFilter;
import net.rim.device.api.ui.text.NumericTextFilter;
import net.rim.device.api.ui.container.MainScreen;

public class TableScreen extends MainScreen implements FieldChangeListener,FocusChangeListener {


/// USER INPUT ///
EditField custnbrField; /// 1234567890
EditField principalField; /// $10,000.00
EditField annintrateField; //// 10.00%
EditField amortprdField; /// 3

/// CALCULATIONS ///
EditField effannintrateField; // ROUND((1+mthlyintfactor)^12-1,4)....Result = 10.25%
EditField mthlyintfactorField; // ((1+(annintrate/2))^2)^(1/12)-1).....Result = 0.008164846%
EditField mthsamortField; // amortprd*12......Result = 36 mths
EditField mthlypaymentField; // (principal * mthlyintfactor)/(1-(1+mthlyintfactor)^(-mthsamort)).....Result = $321.7234593
EditField rndnearestcentField; // ROUND(mthlypayment,2).....Result = $321.72
EditField rndnearestdollarField; // ROUND(rndnearestcent,0)..... Result = $322.00

public TableScreen() {
TextFilter numeric = new NumericTextFilter(NumericTextFilter.ALLOW_DECIMAL) ;
custnbrField = new EditField("Customer Number: " , "");
custnbrField.setFilter(TextFilter.get(TextFilter.N UMERIC)); // no decimal
add(custnbrField);

principalField = new EditField("Initial Principal: $ " , "");
add(principalField);

annintrateField = new EditField("Annual Interest Rate: % " , "");
annintrateField.setFilter(numeric);
add(annintrateField);

amortprdField = new EditField("Amortization Period: (yrs) " , "");
amortprdField.setFilter(TextFilter.get(TextFilter. NUMERIC)); // no decimal
add(amortprdField);

effannintrateField = new EditField("Effective Annual Interest Rate: %" + aa );
effannintrateField.setFilter(numeric);
add(effannintrateField);

mthlyintfactorField = new EditField("Monthly Interest Factor: " + bb );
add(mthlyintfactorField);

mthsamortField = new EditField("Months to Amortization: "+ cc );
add(mthsamortField);


//// Monthly Payment to be displayed automatically after Monthly Interest Factor has been calculated
mthlypaymentField = new EditField("Periodic Monthly Payment: $"+ dd );
add(mthlypaymentField);

rndnearestcentField = new EditField("Rounded to nearest cent: $" + ee );
add(rndnearestcentField);

rndnearestdollarField = new EditField(("Rounded to nearest dollar:$" + ff );
add(rndnearestdollarField);

}
}
public void focusChanged(Field field, int eventType);
if (eventType == FOCUS_LOST) {
if (field == mthlypayment) {
float aa = ROUND((1+mthlyintfactor)^12-1,4);
float bb = ((1+(annintrate/2))^2)^(1/12)-1);
float cc = amortprd*12;
float dd = (principal * bb)/(1-(1+ bb)^(- cc));
float ee = ROUND(dd,2);
float ff = ROUND(dd,rndnearestcent,0);
}
}
}
Attached Images
File Type: png excel table.png (28.7 KB, 6 views)
Offline  
Old 09-30-2010, 09:48 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Post the compiler message.
Offline  
Old 09-30-2010, 11:15 AM   #3 (permalink)
New Member
 
Join Date: Sep 2010
Location: Canada
Model: 8330
PIN: N/A
Carrier: Telus
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the compile list. Appreciate your assistance.....

Building LoanTable
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=LoanTable LoanTable.rapc warnkey=0x52424200;0x52525400;0x52435200 "C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableApp.java" "C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java"
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:6 5: ')' expected
rndnearestdollarField = new EditField(("Rounded to nearest dollar:$" + ff );
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 0: class or interface expected
public void focusChanged(Field field, int eventType);
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 1: class or interface expected
if (eventType == FOCUS_LOST) {
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 4: class or interface expected
float bb = ((1+(annintrate/2))^2)^(1/12)-1);
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 5: class or interface expected
float cc = amortprd*12;
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 6: class or interface expected
float dd = (principal * bb)/(1-(1+ bb)^(- cc));
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 7: class or interface expected
float ee = ROUND(dd,2);
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 8: class or interface expected
float ff = ROUND(dd,rndnearestcent,0);
^
C:\AFM BB APS\AFMTEST\test3\Test4\com\src\TableScreen.java:7 9: class or interface expected
}
^
9 errors
Error!: Error: java compiler failed: javac -source 1.3 -target 1.1 -g -O -d C:\Users\ALEXMC~1\AppData\Local\Temp\rapc_6de6b9bf .dir -boot ...
Error while building project
Offline  
Old 09-30-2010, 12:24 PM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

First issue:

rndnearestdollarField = new EditField(("Rounded to nearest dollar:$" + ff );

should be

rndnearestdollarField = new EditField("Rounded to nearest dollar:$" + ff );

(you have an extra '(' in there)...
Offline  
Old 09-30-2010, 01:41 PM   #5 (permalink)
New Member
 
Join Date: Sep 2010
Location: Canada
Model: 8330
PIN: N/A
Carrier: Telus
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

First issue fixed....Thanks!
Offline  
Old 09-30-2010, 03:39 PM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.text.TextFilter;
import net.rim.device.api.ui.text.NumericTextFilter;
import net.rim.device.api.ui.container.MainScreen;

public class TableScreen extends MainScreen  implements FocusChangeListener {


 /// USER INPUT ///
  EditField custnbrField; /// 1234567890
  EditField principalField; /// $10,000.00
  EditField annintrateField; //// 10.00%
  EditField amortprdField; /// 3
  float aa=0,bb=0,cc=0,dd=0,ee=0,ff=0;
  
  /// CALCULATIONS ///
  EditField effannintrateField; // ROUND((1+mthlyintfactor)^12-1,4)....Result = 10.25%
  EditField mthlyintfactorField; // ((1+(annintrate/2))^2)^(1/12)-1).....Result = 0.008164846%
  EditField mthsamortField; // amortprd*12......Result = 36 mths
  EditField mthlypaymentField; // (principal * mthlyintfactor)/(1-(1+mthlyintfactor)^(-mthsamort)).....Result = $321.7234593
  EditField rndnearestcentField; // ROUND(mthlypayment,2).....Result = $321.72
  EditField rndnearestdollarField; // ROUND(rndnearestcent,0)..... Result = $322.00

        public TableScreen() {
        TextFilter numeric = new NumericTextFilter(NumericTextFilter.ALLOW_DECIMAL); 
            custnbrField = new EditField("Customer Number:  " , "");
            custnbrField.setFilter(TextFilter.get(TextFilter.NUMERIC)); // no decimal
            add(custnbrField);
         
            principalField = new EditField("Initial Principal: $ " , "");
            add(principalField);
         
            annintrateField = new EditField("Annual Interest Rate: % " , "");
            annintrateField.setFilter(numeric);
            add(annintrateField);
         
            amortprdField = new EditField("Amortization Period: (yrs) " , "");
            amortprdField.setFilter(TextFilter.get(TextFilter.NUMERIC)); // no decimal
            add(amortprdField);
         
            effannintrateField = new EditField("Effective Annual Interest Rate: %" + aa,"" );
            effannintrateField.setFilter(numeric);
            add(effannintrateField);
         
            mthlyintfactorField = new EditField("Monthly Interest Factor: " + bb,"" );
            add(mthlyintfactorField); 
         
            mthsamortField = new EditField("Months to Amortization: "+ cc,"" );
            add(mthsamortField); 
         
           
//// Monthly Payment to be displayed automatically after Monthly Interest Factor has been calculated
            mthlypaymentField = new EditField("Periodic Monthly Payment: $"+ dd,"" );
            add(mthlypaymentField); 
         
            rndnearestcentField = new EditField("Rounded to nearest cent: $" + ee ,"");
            add(rndnearestcentField); 
         
            rndnearestdollarField = new EditField("Rounded to nearest dollar:$" + ff ,"");
            add(rndnearestdollarField); 
 
      }
EditField has two arguments. See the definition: EditField(String label, String initialValue)
I didn't understand the calculation below but you should use getText() method of EditField to get the value and use Float.parseFloat() to change into float value.

Also you can use Math.round(), Math.ceil(), Math.floor(), Math.pow() method of Java for calculation. I didn't try these.

Code:
   
public void focusChanged(Field field, int eventType){
if (eventType == FOCUS_LOST) {
if (field == mthlypaymentField) {

aa = ROUND((1 + Float.parseFloat(mthlyintfactorField.getText()))^12-1,4);
bb = ((1+(Float.parseFloat(annintrateField.getText())/2))^2)^(1/12)-1);
cc = Float.parseFloat(annintrateField.getText())*12;
dd = (Float.parseFloat(principalField.getText()) * bb)/(1-(1+ bb)^(- cc));
ee = ROUND(dd,2);
ff = ROUND(dd,Float.parseFloat(rndnearestcentField.getText()),0); 
                    }
        }
    }
}

Last edited by romah : 09-30-2010 at 03:46 PM.
Offline  
Old 09-30-2010, 04:10 PM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is one class net.rim.device.api.util.MathUtilities which provides some mathematical functions like MathUtilities.round(), MathUtilities.pow() etc. You can use those methods for your calculation.

Hope this will solve your problem.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright © 2004-2014 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.