Why is this algorithm in Java not running? [closed]

-1
import java.util.Scanner;

public class CalculoSalarioLiquido {

    public static void main (String args []) {

        System.out.println("Programa para calcular o Salário Líquido: ");

        System.out.println("Escreva o Número de Horas Trabalhadas pelo Funcionário: ");
        Scanner sc = new Scanner (System.in);
        double numerodehorastrabalhadas = sc.nextInt();

        System.out.println("Escreva o Número de Horas Extras Trabalhadas pelo Funcionário: ");
        double numerodehorasextras = sc.nextInt();

    **//Tem vários erros nestes quatro System.out.println. Estou com problemas na importação dos métodos, para depois imprimir os resultados. Erros de not a statement.** 
        System.out.println ("Salário Bruto: " (calcularsalariodofuncionario(numeroDeHorasTrabalhadas,numeroDeHorasExtras)));
        System.out.println ("Imposto de Renda: "calcularImpostodeRenda(salariobruto));
        System.out.println ("Seguro Social: " calcularSeguridadeSocial(salariobruto));
        System.out.println ("Salário Líquido: " calcularSalarioLiquido(salariobruto, seguridadesocial, impostoderenda));
    }

    public static double calcularsalariodofuncionario (double numeroDeHorasTrabalhadas, double numeroDeHorasExtras) {

        double salarioinicial = numerodehorastrabalhadas * 18.6;
        double salariosdashorasextras = 5.7 * numerodehorasextras;

        double salariobruto = salarioinicial + salariosdashorasextras;
        return salariobruto;
        }

    public static double calcularImpostoDeRenda(double salariobruto){
        double impostoderenda = salariobruto * 0.49;
        return impostoderenda;
    }

    public static double calcularSeguridadeSocial (double salariobruto){
        double seguridadesocial = salariobruto * 0.94;
        return seguridadesocial;
    }

    public static double calcularSalarioLiquido (double salariobruto, double seguridadesocial, double impostoderenda){
    double salarioliquido = salariobruto - seguridadesocial - impostoderenda;
    return salarioliquido;
    }
}

How to fix?

    
asked by anonymous 17.07.2016 / 00:25

2 answers

4

The code is full of typos. Programming is detail. Need to organize the code, pay attention to what you are typing. Do not just drop a text and you're done. You have to pay attention, be careful, be capricious. You have to read the errors, interpret them and correct them.

You can be angry with me, but I will say something that is the most important at the moment and what else will help you: you have to change the way you program, what you are doing is just writing codes, not creating programs. This way will not get you anywhere.

Analyze character by character that I've changed. Yes, you will lose half an hour doing this, but you will learn something. If you think it is a waste of time to do this, you will still have difficulties. Most are just uppercase and lowercase, but there is also a lack of concatenation of the text to be printed and the lack of storage of function results in local variables.

You really need to adopt a pattern of variable names. Try using camelCase in all variable names. Be consistent! I did not do it because it's too much wrong, make you as an exercise. Do not miss out! It may seem silly to organize like this, but over time you will find it very important to make reading easier and finding errors more easily. All experienced programmers organize their code a lot. Start doing it right away.

I will not even mention the wrong use of double for monetary values, you're not ready for this yet.

import java.util.Scanner;

class CalculoSalarioLiquido {

    public static void main(String args []) {

        System.out.println("Programa para calcular o Salário Líquido: ");

        System.out.println("Escreva o Número de Horas Trabalhadas pelo Funcionário: ");
        Scanner sc = new Scanner(System.in);
        double numerodehorastrabalhadas = sc.nextInt(); // <===== nome ruim

        System.out.println("Escreva o Número de Horas Extras Trabalhadas pelo Funcionário: ");
        double numerodehorasextras = sc.nextInt();

        double salariobruto = calcularsalariodofuncionario(numerodehorastrabalhadas, numerodehorasextras);
        double impostoderenda = calcularImpostoDeRenda(salariobruto);
        double seguridadesocial = calcularSeguridadeSocial(salariobruto);
        System.out.println("Salário Bruto: " + salariobruto);
        System.out.println("Imposto de Renda: " + impostoderenda);
        System.out.println("Seguro Social: " + seguridadesocial);
        System.out.println("Salário Líquido: " + calcularSalarioLiquido(salariobruto, seguridadesocial, impostoderenda));
    }

    public static double calcularsalariodofuncionario(double numeroDeHorasTrabalhadas, double numeroDeHorasExtras) { // Nomes bons
        double salarioinicial = numeroDeHorasTrabalhadas * 18.6;
        double salariosdashorasextras = 5.7 * numeroDeHorasExtras;
        double salariobruto = salarioinicial + salariosdashorasextras;
        return salariobruto;
    }

    public static double calcularImpostoDeRenda(double salariobruto) {
        double impostoderenda = salariobruto * 0.49;
        return impostoderenda;
    }

    public static double calcularSeguridadeSocial(double salariobruto) {
        double seguridadesocial = salariobruto * 0.94;
        return seguridadesocial;
    }

    public static double calcularSalarioLiquido(double salariobruto, double seguridadesocial, double impostoderenda) {
        double salarioliquido = salariobruto - seguridadesocial - impostoderenda;
        return salarioliquido;
    }
}

See working on ideone and on CodingGround .

    
17.07.2016 / 00:29
2

For you to use a variable, it has to be in the scope of the method, in this case, the declaration of the wage variable was missing. Java is a language that has "Case sensitive", that is, it has a difference between upper and lower case letters. The parameters that you are passing in System.out.println ("Gross Salary:" (calcularsalongeruniversal (Number of Working Hours, Number of HoursExtras)); is different from that declared, and to show String and values on the same line you must use the + sign to concatenate the values. The names of your names that you are calling in System.out.println, are also different from what was declared. Make those fixes that will work.

    
17.07.2016 / 03:31