La vai o codigo.
[code]
import javax.microedition.lcdui.;
import javax.microedition.midlet.;
import java.lang.Math;
public class ProjetoWill extends MIDlet implements CommandListener
{
Display tela;
Form login, resultado;
TextField periodo, valordepositado, valorpretendido;
StringItem resultadoMsg;
Command sair, proximo;
String teste, teste2;
int n, varValor1, varValor2, varResult;
double p, f;
double result1, result2, result3, result4;
public ProjetoWill()
{
// inicializar Commands
this.sair = new Command("Sair", Command.EXIT, 0);
this.proximo = new Command("Prox", Command.SCREEN, 1);
// form de login
this.login = new Form("Login");
this.periodo = new TextField("periodo:", "", 20, TextField.ANY);
this.valordepositado = new TextField("valordepositado:", "", 20, TextField.ANY);// | TextField.PASSWORD);
this.valorpretendido = new TextField("valorpretendido:", "", 20, TextField.ANY);
//adiciona-se os componentes ao Form Login
this.login.append(this.periodo);
this.login.append(this.valordepositado);
this.login.append(this.valorpretendido);
this.login.addCommand(this.sair);
this.login.addCommand(this.proximo);
this.login.setCommandListener(this);
// form de resultado
this.resultado = new Form("Resultado");
this.resultadoMsg = new StringItem("","");
//adiciona-se o componente ao Form Resultado
this.resultado.append(this.resultadoMsg);
this.resultado.addCommand(this.sair);
this.resultado.setCommandListener(this);
}
public void setperiodo(){
}
public double exp(double x, int y){
double aux;
int i;
aux = 1;
i = 1;
while (i == y){
aux = aux*x;
}
result4 = aux;
return result4;
}
public double func(double i, double w, int n){
double aux;
double aux2;
aux = i + 1;
aux2 = exp(aux, n);
double result3 = (aux2 - (w*i)) -1;
return result3;
}
public double devfunc(double i, double w, int n){
int aux;
double aux1;
double aux3;
aux1 = 1 + i;
aux = n - 1;
aux3 = exp(aux1,aux);
result2 = (n * aux3) - w;
return result2;
}
public double raphson(int n, double p, double f){
int k = 1;
int maxint = 100;
double erro = 0.1;
double precisao = 0.000001;
double w = f/p;
double i = 100;
double fa = func(i,w,n);
while((erro > precisao) && (k < maxint))
{
fa = func(i,w,n);
double devfa = devfunc(i,w,n);
double result1 = i-(fa/devfa);
erro = (i-result1);
i = result1;
k += 1;
}
return result1;
}
public void startApp()
{
this.tela = Display.getDisplay(this);
this.tela.setCurrent(this.login);
}
public void pauseApp()
{
}
public void destroyApp(boolean condicional)
{
}
public void commandAction(Command c, Displayable d)
{
if (c == this.sair) {
this.destroyApp(true);
this.notifyDestroyed();
}
String str1 = periodo.getString();
String str2 = valordepositado.getString();
String str3 = valorpretendido.getString();
n = 0;
p = 0;
double f = 0;
n = Integer.parseInt(str1);
p = Double.parseDouble(str2);
f = Double.parseDouble(str3);
double varResult = raphson(n,p,f);
if (c == this.proximo) {
//O Label sempre aparecerá antes do Text não importando
//a ordem que vc adicione ele ao componente
//faça o teste trocando de ordem as chamdas.
//teste = "opa";
this.resultadoMsg.setLabel("O Resultado é: "+varResult);//this.periodo.getString()+" ");
//this.resultadoMsg.setText(this.valordepositado.getString());
this.tela.setCurrent(this.resultado);
}
}
}[/code]