Calculate Car Preventive Maintenance in JavaFX

0

First of all, good morning, everyone!

Well today I have a small problem to solve with a program that I am asked to develop in Java is to calculate the figure in mileage that a car should be maintenance . For example, each vehicle is serviced at 5,000 Km . Which means that a car with a current mileage of 10,000 Km must go to maintenance at 15,000 Km . The alerts will be sent according to the value of the current mileage field. But my teacher wants to see a field that shows the mileage in which the car should go to maintenance in base at 5000 Km . Example:

  • Auto: Toyota Corolla

  • Board: A121212

  • Km Current: 5500

  • KmProxMaintenance: ? Here I show my interface what is enclosed in Red is the data that I use static to calculate when it has already traveled the 5000 km.

5000 in the red circle is the basis for calculating the 5000 km route and sending the alerts but as I said before, the teacher wants to see the next mileage according to the current mileage or how I have set it KmFinal

This is my code:

@FXML
public void RE() {
    try {

        Integer n1 = Integer.parseInt(txt_KmIni.getText());//Kilometraje Inicial de la jornada
        Integer n2 = Integer.parseInt(txt_KmFin.getText());//Kilometraje Final fin de jornada
        Integer resta1 = n2 - n1;//Resta de Kilometraje final menos inicial = Kilometraje Recorrido durante la jornada
        String total1 = Integer.toString(resta1);
        txt_KmRec.setText(String.valueOf(total1)); //Total asignado al campo Kilometraje Recorrido

        Integer Recorrido = Integer.parseInt(txt_KmRec.getText()); //Campo Kilometraje recorrdio
        Integer RecorridoTtal = Integer.parseInt(txt_KmRecoTotal.getText());//Campo Kilometraje Recorrido Total por cada vahiculo Proviene de suma en MySQL
        Integer ProxMantenimiento = Integer.parseInt(txt_ProxMant.getText());//Campo con valor de proximo mantenimiento en este caso 5,000 como base

        Integer Calculado1 = Recorrido + RecorridoTtal; //Recorrido del dia + Recorrido Total del vehiculo -> (Dato de MySQL)
        Integer Calculado2 = ProxMantenimiento - Calculado1;//Resta del campo Proximo Mantenimiento - Calculado1 que es la suma del kilometraje recorrido del dia mas el total del vehiculo
        txt_KmRest.setText(String.valueOf(Calculado2)); //Aqui es donde seteo el resultado de Calculado2 que es el kilometraje restante para el proxmantenimiento segun esto envio alertas.

    } catch (Exception e) {

    }
}
    
asked by Riddick 18.10.2017 в 18:58
source

1 answer

0

To get the next maintenance you can do this

Divide the total number downwards by 5000, then add one and multiply it by 5000, finally subtract the current amount,

5500/5000 (rounded down) = 1; 1 + 1 = 2; 2 * 5000 = 10000; (the next update); 10000 - 5500 = 4500 (how much is missing) This could be left in java like this

Integer Calculado1 = Recorrido + RecorridoTtal; //Recorrido del dia + Recorrido Total del vehiculo -> (Dato de MySQL)
float maintenanceNum = Calculado1 / 5000
int nextMaintenance = (Math.round(maintenance) + 1) * 500; // te dirá el km de tu próximo mantenimiento, ya sea 5,000 10,000
int kmToMaintenance = nextMaintenance - Calculado1; // te dirá los km restantes para mantenimiento

Tip: for good programming practices the variables are defined with loweCamelCase, ie the first letter in lowercase, only the classes are defined with UpperCamelCase. if you are not going to use the int as a class, use it primitively (int instead of Integer);

    
answered by 18.10.2017 / 20:24
source