java.lang.Nillpointerexception error

Asked

Viewed 88 times

-1

My code is returning this error:

Exception in thread "main" java.lang.Nillpointerexception at Banco.java:36

I’ve redone the whole project, all the classes, I’ve watched the videos countless times, but I can’t identify the cause of the error.

My code:

public class ContaJ implements Conta {

private double saldo = 0.0;

// Taxa de juros aplicada
public static final double I = 0.05;

public void extrato() {
System.out.println("Saldo da conta F" + saldo);

}


public void deposito(double valor) {
saldo = saldo + valor;
System.out.println("Valor depositado:" + valor);
}


public void saque(double valor) {
if (valor <= saldo) { 
saldo = saldo - valor;
System.out.println("Valor sacado:"+ valor);
}
else {
System.out.println("Saldo insuficinete");
}
}

public double simulaEmprestimo (double cf, int n) {
return I/(1-1/Math.pow(1+I, n))*cf;
}
}

====================================================
public class ContaF implements Conta {

private double saldo = 0.0;

// Taxa de juros aplicada
public static final double I = 0.03;

public void extrato() {
System.out.println("Slado da conta F" + saldo);

}


public void deposito(double valor) {
saldo = saldo + valor;
System.out.println("Valor depositado:" + valor);
}


public void saque(double valor) {
if (valor <= saldo) { 
saldo = saldo - valor;
System.out.println("Valor sacado:"+ valor);
}
else {
System.out.println("Saldo insuficinete");
}
}

public double simulaEmprestimo (double cf, int n) {
return I/(1-1/Math.pow(1+I, n))*cf;
}
}

=============================================
public interface Conta {

public void extrato();
public void deposito(double valor);
public void saque(double valor);

// cf = capital financiado, n = meses
public double simulaEmprestimo (double cf, int n);

}

=======================================
import java.util.ArrayList;

public class BAnco {

public static void main (String args[]) {


ArrayList<correntistamae> lista_De_Clientes = new ArrayList<correntistamae>();

Correntista c1 = new Correntista("Matheus", new ContaF());
lista_De_Clientes.add(c1);
Correntista c2 = new Correntista("Arlindo",  new ContaF());
lista_De_Clientes.add(c2);
Correntista c3 = new Correntista("Josefanilda",  new ContaF());
lista_De_Clientes.add(c3);
Correntista c4 = new Correntista("Jucintolucio",  new ContaF());
lista_De_Clientes.add(c4);

Corrrentista_Juridico cJuridico = new Corrrentista_Juridico("ACME LLC", "Pedro",  new ContaJ());
lista_De_Clientes.add(cJuridico);



c1.exibe_Indentfiacao();
c2.exibe_Indentfiacao();
c3.exibe_Indentfiacao();
c4.exibe_Indentfiacao();
cJuridico.exibe_Indentfiacao();

double valorParcela = c1.getConta().simulaEmprestimo(1000.0, 12);
System.out.println(valorParcela); //Dando erro



} 
}

What is causing this error?

1 answer

0

I recommend that you edit your question and post the Correntista class to make a deeper analysis.

However, taking as a reference the simulation method Mprestimo() of the class Contaj and Contaf, your problem may be C1.getConta(), taking into account that Project simulation(1000.0, 12) would compile normally:

double valorParcela = c1.getConta().simulaEmprestimo(1000.0, 12);

Better analysis of the getConta() method of Correntista, because the problem may be there.

Post the Correctional class so we can help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.