Problem with Serialization

0

I have a serialized class which has several attributes, these are static since I need to be modifying them, the problem is that after serialize and save the data, when re-reading all the attributes remain with their default value, in what way can I make those attributes take the value of the data stored previously serialized?

Here's the serialized class:

package Parqueadero;

import java.io.Serializable;

public class Informes implements Serializable {

    //Suma total de dinero
    private static double sdinerot = 0;

    //Suma de dinero por tipo de  clientes 
    private static double sdineroTA = 0;
    private static double sdineroTB = 0;
    private static double sdineroTC = 0;

    //total de clientes segun su tipo 
    private static int tCA = 0, tCB = 0, tCC = 0;

    //Suma de dinero por tipo de vehiculo
    private static double sdinerocarro = 0;
    private static double sdinerocamioneta = 0;
    private static double sdinerobus = 0;
    private static double sdineromoto = 0;

    public double getSdinerot() {
        return sdinerot;
    }

    public void setSdinerot(double total) {
        sdinerot = sdinerot + total;

    }

    public double getSdineroTA() {
        return sdineroTA;
    }

    public void setSdineroTA(double sdineroTA) {
        this.sdineroTA = this.sdineroTA + sdineroTA;
    }

    public double getSdineroTB() {
        return sdineroTB;
    }

    public void setSdineroTB(double sdineroTB) {
        this.sdineroTB = this.sdineroTB + sdineroTB;
    }

    public double getSdineroTC() {
        return sdineroTC;
    }

    public void setSdineroTC(double sdineroTC) {
        this.sdineroTC = this.sdineroTC + sdineroTC;
    }

    public int gettCA() {
        return tCA;
    }

    public void setcCA() {
        tCA++;
    }

    public int gettCB() {
        return tCB;
    }

    public void setcCB() {
        tCB++;
    }

    public int gettCC() {
        return tCC;
    }

    public void setcCC() {
        tCC++;
    }

    public double getSdinerocarro() {
        return sdinerocarro;
    }

    public void setSdinerocarro(double sdinerocarro) {
        this.sdinerocarro = this.sdinerocarro + sdinerocarro;
    }

    public double getSdinerocamioneta() {
        return sdinerocamioneta;
    }

    public void setSdinerocamioneta(double sdinerocamioneta) {
        this.sdinerocamioneta = this.sdinerocamioneta + sdinerocamioneta;
    }

    public double getSdinerobus() {
        return sdinerobus;
    }

    public void setSdinerobus(double sdinerobus) {
        this.sdinerobus = this.sdinerobus + sdinerobus;
    }

    public double getSdineromoto() {
        return sdineromoto;
    }

    public void setSdineromoto(double sdineromoto) {
        this.sdineromoto = this.sdineromoto + sdineromoto;
    }

    public double getPromedioClienteA() {
        if (tCA == 0) {
            return 0;
        }
        return (sdineroTA / tCA);
    }

    public double getPromedioClienteB() {
        if (tCB == 0) {
            return 0;
        }
        return (sdineroTB / tCB);
    }

    public double getPromedioClienteC() {
        if (tCC == 0) {
            return 0;
        }
        return (sdineroTC / tCC);
    }

}
    
asked by Steven Camargo 08.11.2017 в 03:40
source

1 answer

0

Do not make them static. You really have no reason to make them static, since the methods that access them are not, and therefore it means that you are creating an instance (an object) of that class to work with.

    
answered by 08.11.2017 в 09:07