BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-30-2010, 08:36 AM   #1
Alex McQuaid
New Member
 
Join Date: Sep 2010
Location: Canada
Model: 8330
PIN: N/A
Carrier: Telus
Posts: 10
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, 08:48 AM   #2
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

Post the compiler message.
Offline  
Old 09-30-2010, 10:15 AM   #3
Alex McQuaid
New Member
 
Join Date: Sep 2010
Location: Canada
Model: 8330
PIN: N/A
Carrier: Telus
Posts: 10
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, 11:24 AM   #4
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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, 12:41 PM   #5
Alex McQuaid
New Member
 
Join Date: Sep 2010
Location: Canada
Model: 8330
PIN: N/A
Carrier: Telus
Posts: 10
Default

First issue fixed....Thanks!
Offline  
Old 09-30-2010, 02:39 PM   #6
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
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 02:46 PM..
Offline  
Old 09-30-2010, 03:10 PM   #7
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


CBB61 250V  Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF picture

CBB61 250V Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF

$129.95



6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF picture

6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF

$155.59



45/5 MFD ±5% Dual Run Capacitor 370 450 VAC CBB65 AC Motor HVAC 45+5 uF Fan 10pk picture

45/5 MFD ±5% Dual Run Capacitor 370 450 VAC CBB65 AC Motor HVAC 45+5 uF Fan 10pk

$89.99



5pc Radial Electrolytic Capacitor 250V 100V 50V 25V 16V 0.22uF-4700uF 10000uF picture

5pc Radial Electrolytic Capacitor 250V 100V 50V 25V 16V 0.22uF-4700uF 10000uF

$22.99



70UF 250VAC Wire Motor Run Capacitor 250V AC CBB60 70 UF Round Black 50/60HZ Cap picture

70UF 250VAC Wire Motor Run Capacitor 250V AC CBB60 70 UF Round Black 50/60HZ Cap

$11.75



5 MFD AC Capacitor, 5uF ±5% 370VAC/440 Volt Oval Run Start Capacitor  picture

5 MFD AC Capacitor, 5uF ±5% 370VAC/440 Volt Oval Run Start Capacitor 

$9.97







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