every time I give it to run in eclipse, nothing appears on the console, help

0
package tarea;

public class Trabajador {

public static void main(String[] args) {
    // TODO Auto-generated method stub

}

private long documento;
private String nombre;
double valorHora;
int horasTrabajo; 
long salarioTotal;

void salaraioTotal (){

double salarioTotal = valorHora*horasTrabajo;
System.out.println("salario total" + salarioTotal);

 if(valorHora >= 80){
      System.out.println("salarioTotal"+ 100000);

if(salarioTotal <= 1500000) {
    System.out.println("Deduccion salud"+ (salarioTotal*100)/5 + "rte fuente" + (salarioTotal*100)/0);      

  }else {

 if(salarioTotal >= 1500001 && salarioTotal <= 3000000) {
     System.out.println("deduccion salud" + (salarioTotal*100)/8 + "rte fuente" + (salarioTotal*100)/3);
 }else{

  if(salarioTotal <= 3000000) {
      System.out.println("deduccion salud" + (salarioTotal*100)/12 + "rte fuente" + (salarioTotal*100)/5);


  }


 }

  }


 }
}

  } 
 }
    
asked by santiago londoño velez 18.02.2018 в 21:33
source

2 answers

1

You have nothing in the main ... Obviously nothing will be shown in the console. Your code should go in the main method or you should call some other method that contains your code. Another tip is that you do not use as many if and use the switch statement, also I see that you do not start your variables and try to divide by zero, things that are going to give you more problems.

I leave this example that works, you must change the 0 for another value, I for example I put 10.

public class example {

    public static void main(String[] args) {

        long documento = 12345678;
        String nombre = "Lucas";
        double valorHora = 5.00;
        int horasTrabajo = 8;
        long salarioTotal = 2000;

        if (valorHora >= 80) {
            System.out.println("salarioTotal" + 100000);
        }

        if (salarioTotal <= 1500000) {
            // NO PUEDES DIVIDIR POR CERO ! 
            System.out.println("Deduccion salud" + (salarioTotal * 100) / 5 + "rte fuente" + (salarioTotal * 100) / 10);
        } else {
            if (salarioTotal >= 1500001 && salarioTotal <= 3000000) {
                System.out.println(
                        "deduccion salud" + (salarioTotal * 100) / 8 + "rte fuente" + (salarioTotal * 100) / 3);
            } else {
                if (salarioTotal <= 3000000) {
                    System.out.println(
                            "deduccion salud" + (salarioTotal * 100) / 12 + "rte fuente" + (salarioTotal * 100) / 5);
                }
            }

        }

    }

}

This way, by console, I printed Deduction health40000rte source20000

    
answered by 18.02.2018 / 21:45
source
1

I know it worked for you, but you can take it as a piece of advice, instead of writing the method inside the main, you could have just called it from this one; for example:

public class Trabajador{
   public static void main(String[] args){
      salarioTotal();
   }

   void salarioTotal(){
   ...
   }
}

And finally so that later you do not entangle yourself trying to reread the code, you can make your life easier by using a switch (...) or instead of doing if () {...} else {if () {... }}, you can do it in the following way if () {...} else if () {...}

    
answered by 19.02.2018 в 03:54