Problem with abstract class and interfaces

1

I have written the class code, but it does not work out.

Specifically, in the methods CalularSaldoCC and CalularSaldoCA error occurs that does not recognize MontoApertura . Also, I do not know whether to move it to CuantaBancaria or leave them there.

Abstract class CuentaBancaria

public abstract class CuentaBancaria
{
    private String IdCta;
    private String IdClie;
    private float MontoApertura;
    private float Saldo;

    public CuentaBancaria(String IdCta, String IdClie, float MontoApertura, float Saldo) {
        this.IdCta = IdCta;
        this.IdClie = IdClie;
        this.MontoApertura = MontoApertura;
        this.Saldo = Saldo;
    }
    public String getIdClie()
    {        return IdClie;     }
    public void setIdClie(String IdClie)
    {        this.IdClie = IdClie;    }
    public String getIdCta()
    {        return IdCta;    }
    public void setIdCta(String IdCta)
    {        this.IdCta = IdCta;    }
    public float getMontoApertura()
    {        return MontoApertura;    }
    public void setMontoApertura(float MontoApertura)
    {        this.MontoApertura = MontoApertura;    }
    public float getSaldo()
    {        return Saldo;    }
    public void setSaldo(float Saldo)
    {        this.Saldo = Saldo;    }    
    public abstract float CuentaBancaria(String IdCta, String IdClie, float MontoApertura);
    public void MostrarDatos()    {
        System.out.println("Codigo Cliente: " + getIdClie() + "\nCodigo Cuanta Bancaria: " + getIdCta()
                 + "\nMonto Apertura: " + getMontoApertura() + "\nSaldo: " + getSaldo());    
    }      
}

Class CuentaCorriente

public abstract class CuentaCorriente extends CuentaBancaria implements ICCorriente
{
    private double InteresProrrateado;

    public CuentaCorriente(double InteresProrrateado, String IdCta, String IdClie, float MontoApertura, float Saldo) {
        super(IdCta, IdClie, MontoApertura, Saldo);
        this.InteresProrrateado = InteresProrrateado;
    }

    public double getInteresProrrateado() {
        return InteresProrrateado;
    }

    public void setInteresProrrateado(double InteresProrrateado) {
        this.InteresProrrateado = InteresProrrateado;
    }    

    public float CuentaBancaria(String IdCta, String IdClie, float MontoApertura)
    {
        return MontoApertura;
    }

    @Override
    public double CalculaSaldoCC()
    {
        return (MontoApertura + (MontoApertura*InteresProrrateado));
    }
}

Class CuentaAhorros

public class CuentaAhorros extends CuentaBancaria implements ICAhorros
{
    private double InteresMensual;
    private int CantMeses;

    public CuentaAhorros(double InteresMensual, int CantMeses, String IdCta, String IdClie, float MontoApertura, float Saldo) {
        super(IdCta, IdClie, MontoApertura, Saldo);
        this.InteresMensual = InteresMensual;
        this.CantMeses = CantMeses;
    }

    public int getCantMeses() {
        return CantMeses;
    }

    public void setCantMeses(int CantMeses) {
        this.CantMeses = CantMeses;
    }

    public double getInteresMensual() {
        return InteresMensual;
    }

    public void setInteresMensual(double InteresMensual) {
        this.InteresMensual = InteresMensual;
    }


    @Override
    public double CalculaSaldoCA()
    {
        return (MontoApertura + (CantMeses*InteresMensual));
    }

}

Interfaces

public interface ICCorriente
{
    double CalculaSaldoCC();
}

public interface ICAhorros
{
    double CalculaSaldoCA ();    
}
    
asked by Andres Tapia 14.11.2016 в 00:06
source

1 answer

0
  

In the methods CalularSaldoCC and CalularSaldoCA exit error does not recognize MontoApertura . Also I do not know whether to move it to CuantaBancaria or leave them there.

The variable MontoApertura

private float MontoApertura;

... is private in the class CuantaBancaria , so you can not access it in the classes CuentaCorriente and CuentaAhorros , even if these are classes that inherit from the class CuantaBancaria .

However, class CuantaBancaria includes the methods properties getMontoApertura and setMontoApertura

public float getMontoApertura()
{        return MontoApertura;    }
public void setMontoApertura(float MontoApertura)
{        this.MontoApertura = MontoApertura;    }

... that are public and that are able to read and write to the variable MontoApertura . You can use these methods instead of trying to manipulate the variable MontoApertura directly.

@Override
public double CalculaSaldoCC()
{
    return (this.getMontoApertura() + (this.getMontoApertura()*this.InteresProrrateado));
}

// ...

@Override
public double CalculaSaldoCA()
{
    return (this.getMontoApertura() + (CantMeses*InteresMensual));
}
    
answered by 14.11.2016 / 01:50
source