Java - xq me da error al usar una formula de un metodo anterior

 
Vista:

xq me da error al usar una formula de un metodo anterior

Publicado por carlos (25 intervenciones) el 27/11/2018 17:32:53
a ver estoy haciendo un plazo fijo y tengo que calcular el bº tengo la clase main y otro archivo con la clase plazo fijo quiero usar una formula de un metodo que he usado antes en otro metodo pero me marca error
hay otro archivo de clase que es tiempo pero no afecta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ej1tarea;
 
import java.util.Date;
 
/**
 *
 * @author ck
 */
public class PlazoFijo {
 
    private double cantidad;
    private double interes;
    private Fecha fechaCreacion;
    private int tiempo;
 
    public void setCantidad(double cantidad) {
        this.cantidad = cantidad;
    }
 
    public void setInteres(double interes) {
        this.interes = interes;
    }
 
    public void setFechaCreacion(Fecha fechaCreacion) {
        this.fechaCreacion = fechaCreacion;
    }
 
    public void setTiempo(int tiempo) {
        this.tiempo = tiempo;
    }
 
    public double getCantidad() {
        return cantidad;
    }
 
    public double getInteres() {
        return interes;
    }
 
    public Fecha getFechaCreacion() {
        return fechaCreacion;
    }
 
    public int getTiempo() {
        return tiempo;
    }
 
    public PlazoFijo() {
        cantidad = 0;
        interes = 0;
        fechaCreacion = null;
        tiempo = 0;
    }
 
    public PlazoFijo(double cantidad, double interes, Fecha fechaCreacion, int tiempo) {
        this.cantidad = cantidad;
        this.interes = interes;
        this.fechaCreacion = fechaCreacion;
        this.tiempo = tiempo;
    }
 
    public int mesesParaVencimiento() {
        Date d = new Date();
        int tiempoConsumido = (1 + d.getMonth() + 2000 + d.getYear()/100 * 12) - (fechaCreacion.getMes() + fechaCreacion.getAño() * 12);
        /* la fecha de hoy en meses + 1 porque java empieza a contar los meses
        en 0 ademas sumamos 2000 y partimos de 100 el getyear porque java
        empoeza a contar los años desde 1900*/
        int mesesParaVencimiento = tiempo - tiempoConsumido;
        return mesesParaVencimiento;
    }
 
    public int beneficio() {
        double beneficio = cantidad * Math.pow(1 + interes / 100, tiempoConsumido);
        retunr beneficio;
    }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Billy Joel
Val: 2.665
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

xq me da error al usar una formula de un metodo anterior

Publicado por Billy Joel (876 intervenciones) el 27/11/2018 17:46:57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.Date;
 
public class PlazoFijo {
 
    private double cantidad;
    private double interes;
    private Fecha fechaCreacion;
    private int tiempo;
 
    public void setCantidad(double cantidad) {
        this.cantidad = cantidad;
    }
 
    public void setInteres(double interes) {
        this.interes = interes;
    }
 
    public void setFechaCreacion(Fecha fechaCreacion) {
        this.fechaCreacion = fechaCreacion;
    }
 
    public void setTiempo(int tiempo) {
        this.tiempo = tiempo;
    }
 
    public double getCantidad() {
        return cantidad;
    }
 
    public double getInteres() {
        return interes;
    }
 
    public Fecha getFechaCreacion() {
        return fechaCreacion;
    }
 
    public int getTiempo() {
        return tiempo;
    }
 
    public PlazoFijo() {
        cantidad = 0;
        interes = 0;
        fechaCreacion = null;
        tiempo = 0;
    }
 
    public PlazoFijo(double cantidad, double interes, Fecha fechaCreacion, int tiempo) {
        this.cantidad = cantidad;
        this.interes = interes;
        this.fechaCreacion = fechaCreacion;
        this.tiempo = tiempo;
    }
 
    public int mesesParaVencimiento() {
        Date d = new Date();
        int tiempoConsumido = (1 + d.getMonth() + 2000 + d.getYear() / 100 * 12) - (fechaCreacion.getMes() + fechaCreacion.getAño() * 12);
        /* la fecha de hoy en meses + 1 porque java empieza a contar los meses
           en 0 ademas sumamos 2000 y partimos de 100 el getyear porque java
           empoeza a contar los años desde 1900*/
        int mesesParaVencimiento = tiempo - tiempoConsumido;
        return mesesParaVencimiento;
    }
 
    public double beneficio() {
        double beneficio = cantidad * Math.pow(1 + interes / 100, tiempo);
        return beneficio;
    }
}

En el método beneficio estabas retornando un int, le cambié el tipo de retorno a double;
También tenías una variable tiempoConsumido que no se de donde sale dentro de ese método por lo que asumí que haces referencia a la variable global tiempo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar

xq me da error al usar una formula de un metodo anterior

Publicado por carlos (25 intervenciones) el 27/11/2018 18:02:47
cerrado duda resuleta
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar