#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Posts
    4
    Rep Power
    0

    What is wrong with my code


    Greetings,
    Im from Brazil and can't find help there,Im having issues with my code.
    I would like some help,it's not compipling.

    Here it is

    Code:
    import java.util.Scanner; 
    public class Calculosalarioebeneficios{
    public static void main(String[] args) {
     Scanner console = new Scanner(System.in);
    var
    
    
    int idade,diasmes,diastrabmes,horasdia
    double valhrtrab,salario,inss,fgts
    char d,n
    
    public class Exemplo{public static void main(String args[]{;
    System.out.print("Digite o nome do funcionário: ");
    nome=sc.nextLine();//String;
    System.out.print("Digite a idade do funcionário: ");
    idade=Integer.parselnt(sc.nextLine();
    System.out.print("Digite quantos dias trabalhados no mês: ");
    diastrabmes=Integer.parselnt(sc.nextLine();
    repita;
    System.out.print("Regime de horas trabalhadas por dia. 6 || 8 horas?: ");
    horasdia =Integer.parselnt(sc.nextLine();
    ate ((horasdia = 6) || (horasdia = 8));
    System.out.print("Digite o Turno. D para Diurno e N para Noturno || Pressione S para Sair: ");
    turdiario=sc.nextLine();//String;
    if((turdiario != "D") && (turdiario != "N")) entao;
    System.out.println("Programa Finalizado!!");
    }
    if ((turdiario = "D") && (idade <=50)) entao;
    valhrtrab:= 3;
    senao;
    if ((turdiario = "D") && (idade > 50)) entao;
    valhrtrab:= 3 + (3*0.10);
    }
    if ((turdiario = "N") && (idade <=50)) entao;
    valhrtrab:= 4;
    senao;
    if ((turdiario = "N") && (idade > 50)) entao;
    valhrtrab:= 4 + (4*0.10);
    }
    }
    }
    salario:= (valhrtrab * horasdia* diastrabmes)+ (valhrtrab * horasdia* diastrabmes* 1.5);
    fgts:= salario*0.08;
    if salario<= 1556.94 entao;
    inss:= salario*0.08;
    senao;
    if ((salario >=  1556.95) && (salario <= 2594.92)) entao;
    inss:= salario*0.09;
    senao;
    if ((salario >= 2594.93) && (salario <= 8189.82)) entao;
    inss:= salario*0.11 senao;
    }
    }
    System.out.printl("O salario bruto é: ",salario);
    System.out.printl( "O Total do Depósito do FGTS é: ",fgts);
    System.out.print( "O depósito do INSS é: ", inss);
    	}
    }
    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Posts
    2
    Rep Power
    0
    Can you give us the compiler errors? Hard to tell but looks like you forgot semi-colons when initializing variables at the beginning.

    Also, try to format your code according to standards (with tabs)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Posts
    4
    Rep Power
    0
    Everytime I try to run it it gets worse
    Here it is.
    Thanks in advance

    Code:
    classError(s), warning(s):
    source_file.java:5: error: not a statement
    var
    ^
    source_file.java:5: error: ';' expected
    var
       ^
    source_file.java:8: error: ';' expected
    int idade,diasmes,diastrabmes,horasdia
                                          ^
    source_file.java:9: error: ';' expected
    double valhrtrab,salario,inss,fgts
                                      ^
    source_file.java:10: error: ';' expected
    char d,n
            ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
    ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
          ^
    source_file.java:12: error: not a statement
    public class Exemplo{public static void main(String args[]{;
                 ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
                        ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
                         ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
                                ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
                                      ^
    source_file.java:12: error: ')' expected
    public class Exemplo{public static void main(String args[]{;
                                                       ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
                                                            ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
                                                             ^
    source_file.java:16: error: ')' expected
    idade=Integer.parselnt(sc.nextLine();
                                        ^
    source_file.java:18: error: ')' expected
    diastrabmes=Integer.parselnt(sc.nextLine();
                                              ^
    source_file.java:19: error: not a statement
    repita;
    ^
    source_file.java:21: error: ')' expected
    horasdia =Integer.parselnt(sc.nextLine();
                                            ^
    source_file.java:25: error: not a statement
    if((turdiario != "D") && (turdiario != "N")) entao;
                                                 ^
    source_file.java:28: error: not a statement
    if ((turdiario = "D") && (idade <=50)) entao;
                                           ^
    source_file.java:29: error: illegal start of expression
    valhrtrab:= 3;
              ^
    source_file.java:30: error: not a statement
    senao;
    ^
    source_file.java:31: error: not a statement
    if ((turdiario = "D") && (idade > 50)) entao;
                                           ^
    source_file.java:32: error: illegal start of expression
    valhrtrab:= 3 + (3*0.10);
              ^
    source_file.java:34: error: not a statement
    if ((turdiario = "N") && (idade <=50)) entao;
                                           ^
    source_file.java:35: error: illegal start of expression
    valhrtrab:= 4;
              ^
    source_file.java:36: error: not a statement
    senao;
    ^
    source_file.java:37: error: not a statement
    if ((turdiario = "N") && (idade > 50)) entao;
                                           ^
    source_file.java:38: error: illegal start of expression
    valhrtrab:= 4 + (4*0.10);
              ^
    source_file.java:41: error: class, interface, or enum expected
    }
    ^
    source_file.java:43: error: class, interface, or enum expected
    fgts:= salario*0.08;
    ^
    source_file.java:44: error: class, interface, or enum expected
    if salario<= 1556.94 entao;
    ^
    source_file.java:45: error: class, interface, or enum expected
    inss:= salario*0.08;
    ^
    source_file.java:46: error: class, interface, or enum expected
    senao;
    ^
    source_file.java:47: error: class, interface, or enum expected
    if ((salario >=  1556.95) && (salario <= 2594.92)) entao;
    ^
    source_file.java:48: error: class, interface, or enum expected
    inss:= salario*0.09;
    ^
    source_file.java:49: error: class, interface, or enum expected
    senao;
    ^
    source_file.java:50: error: class, interface, or enum expected
    if ((salario >= 2594.93) && (salario <= 8189.82)) entao;
    ^
    source_file.java:51: error: class, interface, or enum expected
    inss:= salario*0.11 senao;
    ^
    source_file.java:52: error: class, interface, or enum expected
    }
    ^
    source_file.java:55: error: class, interface, or enum expected
    System.out.printl( "O Total do Depósito do FGTS é: ",fgts);
    ^
    source_file.java:56: error: class, interface, or enum expected
    System.out.print( "O depósito do INSS é: ", inss);
    ^
    source_file.java:57: error: class, interface, or enum expected
    	}
    	^
    44 errors
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Posts
    4
    Rep Power
    0
    If it does Help this code is converted from a portugol code.
    I'll list it below,I might have converted it the wrong way.

    Code:
    algoritmo "Cálculo de salário e benefícios"
    // Função :Cálcular de forma correta o salário e benefício de seus funcionários
    // Autor :
    // Data :
    // Seção de Declarações
    
    var
    
    nome:caracter
    idade:inteiro
    valhrtrab:real
    diasmes:inteiro
    d:caracter
    n:caracter
    turdiario:caracter
    diastrabmes: inteiro
    horasdia: inteiro
    salario: real
    inss: real
    fgts:real
    inicio
    escreva("Digite o nome do funcionário: ")
    leia(nome)
    escreva("Digite a idade do funcionário: ")
    leia(idade)
    escreva("Digite quantos dias trabalhados no mês: ")
    leia(diastrabmes)
    repita
    escreva("Regime de horas trabalhadas por dia. 6 ou 8 horas?: ")
    leia(horasdia)
    ate ((horasdia = 6) ou (horasdia = 8))
    escreva("Digite o Turno. D para Diurno e N para Noturno ou Pressione S para Sair: ")
    leia(turdiario)
    se ((turdiario <> "D") e (turdiario <> "N")) entao
    escreval("Programa Finalizado!!")
    fimse
    se ((turdiario = "D") e (idade <=50)) entao
    valhrtrab:= 3
    senao
    se ((turdiario = "D") e (idade > 50)) entao
    valhrtrab:= 3 + (3*0.10)
    fimse
    se ((turdiario = "N") e (idade <=50)) entao
    valhrtrab:= 4
    senao
    se ((turdiario = "N") e (idade > 50)) entao
    valhrtrab:= 4 + (4*0.10)
    fimse
    fimse
    fimse
    salario:= (valhrtrab * horasdia* diastrabmes)+ (valhrtrab * horasdia* diastrabmes* 1.5)
    fgts:= salario*0.08
    se salario<= 1556.94 entao
    inss:= salario*0.08
    senao
    se ((salario >=  1556.95) e (salario <= 2594.92)) entao
    inss:= salario*0.09
    senao
    se ((salario >= 2594.93) e (salario <= 8189.82)) entao
    inss:= salario*0.11 senao
    fimse fimse
    fimse
    escreval("O salario bruto é: ",salario)
    escreval( "O Total do Depósito do FGTS é: ",fgts)
    escreva( "O depósito do INSS é: ", inss)
    fimalgoritmo
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Posts
    2
    Rep Power
    0
    Originally Posted by silvio232
    Everytime I try to run it it gets worse
    Here it is.
    Thanks in advance

    Code:
    classError(s), warning(s):
    source_file.java:5: error: not a statement
    var
    ^
    source_file.java:5: error: ';' expected
    var
       ^
    source_file.java:8: error: ';' expected
    int idade,diasmes,diastrabmes,horasdia
                                          ^
    source_file.java:9: error: ';' expected
    double valhrtrab,salario,inss,fgts
                                      ^
    source_file.java:10: error: ';' expected
    char d,n
            ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
    ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
          ^
    source_file.java:12: error: not a statement
    public class Exemplo{public static void main(String args[]{;
                 ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
                        ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
                         ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
                                ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
                                      ^
    source_file.java:12: error: ')' expected
    public class Exemplo{public static void main(String args[]{;
                                                       ^
    source_file.java:12: error: illegal start of expression
    public class Exemplo{public static void main(String args[]{;
                                                            ^
    source_file.java:12: error: ';' expected
    public class Exemplo{public static void main(String args[]{;
                                                             ^
    source_file.java:16: error: ')' expected
    idade=Integer.parselnt(sc.nextLine();
                                        ^
    source_file.java:18: error: ')' expected
    diastrabmes=Integer.parselnt(sc.nextLine();
                                              ^
    source_file.java:19: error: not a statement
    repita;
    ^
    source_file.java:21: error: ')' expected
    horasdia =Integer.parselnt(sc.nextLine();
                                            ^
    source_file.java:25: error: not a statement
    if((turdiario != "D") && (turdiario != "N")) entao;
                                                 ^
    source_file.java:28: error: not a statement
    if ((turdiario = "D") && (idade <=50)) entao;
                                           ^
    source_file.java:29: error: illegal start of expression
    valhrtrab:= 3;
              ^
    source_file.java:30: error: not a statement
    senao;
    ^
    source_file.java:31: error: not a statement
    if ((turdiario = "D") && (idade > 50)) entao;
                                           ^
    source_file.java:32: error: illegal start of expression
    valhrtrab:= 3 + (3*0.10);
              ^
    source_file.java:34: error: not a statement
    if ((turdiario = "N") && (idade <=50)) entao;
                                           ^
    source_file.java:35: error: illegal start of expression
    valhrtrab:= 4;
              ^
    source_file.java:36: error: not a statement
    senao;
    ^
    source_file.java:37: error: not a statement
    if ((turdiario = "N") && (idade > 50)) entao;
                                           ^
    source_file.java:38: error: illegal start of expression
    valhrtrab:= 4 + (4*0.10);
              ^
    source_file.java:41: error: class, interface, or enum expected
    }
    ^
    source_file.java:43: error: class, interface, or enum expected
    fgts:= salario*0.08;
    ^
    source_file.java:44: error: class, interface, or enum expected
    if salario<= 1556.94 entao;
    ^
    source_file.java:45: error: class, interface, or enum expected
    inss:= salario*0.08;
    ^
    source_file.java:46: error: class, interface, or enum expected
    senao;
    ^
    source_file.java:47: error: class, interface, or enum expected
    if ((salario >=  1556.95) && (salario <= 2594.92)) entao;
    ^
    source_file.java:48: error: class, interface, or enum expected
    inss:= salario*0.09;
    ^
    source_file.java:49: error: class, interface, or enum expected
    senao;
    ^
    source_file.java:50: error: class, interface, or enum expected
    if ((salario >= 2594.93) && (salario <= 8189.82)) entao;
    ^
    source_file.java:51: error: class, interface, or enum expected
    inss:= salario*0.11 senao;
    ^
    source_file.java:52: error: class, interface, or enum expected
    }
    ^
    source_file.java:55: error: class, interface, or enum expected
    System.out.printl( "O Total do Depósito do FGTS é: ",fgts);
    ^
    source_file.java:56: error: class, interface, or enum expected
    System.out.print( "O depósito do INSS é: ", inss);
    ^
    source_file.java:57: error: class, interface, or enum expected
    	}
    	^
    44 errors
    You need to fix all of the errors, there are many syntax problems. Are you new to Java?

    What is "var" in class body? Should probably just delete it.

    Every instruction has to end in either a semi-colon, or a curly brace (if block statement).

    "public class Exemplo{public static void main(String args[]{;" is not valid Java. You want:

    Code:
    public class Exemplo{
         public static void main(String args[]){
               // code in here
         }
    }
    Go through each compiler error, and google it if you don't understand. You'll learn alot from it.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Location
    India
    Posts
    200
    Rep Power
    4
    First look at the code and I see numerous errors in the code. Yes errors, syntactical ones; the ones that should be detected and corrected at compile-time.

    In the first few lines, I see that you've declared a class, declared a main() method in it, declared another class (i.e. a nested-class) in it for reasons I can't comprehend.

    In the body of the first main method:
    Code:
    public class Calculosalarioebeneficios{
        public static void main(String[] args) {
            Scanner console = new Scanner(System.in);
    var
    
    
    int idade,diasmes,diastrabmes,horasdia
    double valhrtrab,salario,inss,fgts
    char d,n
    You instantiate a Scanner and after that it's all gibberish.. stuff that I can't understand... perhaps no one can... except you.

    And then the nested-class stuff; well I don't know what you're doing there and frankly I don't know unless you explain what you were trying to do! What were you trying to accomplish? What is the required behavior? I can't read your comments unless you use English.

    And no I won't try to compile your program. It won't compile, not in its current state.

IMN logo majestic logo threadwatch logo seochat tools logo