• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong with my code  RSS feed

 
marllon saintz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


Thanks

 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the compiler should be giving you error messages about what is wrong with your code. Didn't you see them?

I can tell you that you don't use ":=" in Java to assign a value to a variable, for one thing. But it would be more practical for you to first read the error messages and then if you don't understand them (a very common situation for beginners) you should post the messages here along with your question. After all the error messages are supposed to provide information about the error, right?
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You have instructions that aren't correctly terminated with semicolon. You are using keywords that don't exist. You are misspelling some method names. You have a class definition within a method class -- which I am not sure is what you intended. Your structure for the "if" statement is incorrect. And as Paul already mentioned, there is no such a thing as the ":=" operator.

Henry
 
marllon saintz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:But the compiler should be giving you error messages about what is wrong with your code. Didn't you see them?

I can tell you that you don't use ":=" in Java to assign a value to a variable, for one thing. But it would be more practical for you to first read the error messages and then if you don't understand them (a very common situation for beginners) you should post the messages here along with your question. After all the error messages are supposed to provide information about the error, right?

Everytime I try to run it it gets worse
Here it is.
Thanks in advance

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
 
marllon saintz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
f it does Help this code is converted from a portugol code.
I'll list it below,I might have converted it the wrong way.

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
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marllon saintz wrote:I might have converted it the wrong way.


Yes, that's definitely true. Let's just take the first few error messages:

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


So, "var" doesn't mean anything in Java. So don't put that in.

And when it says "';' expected" that means that Java statements have to end with a semi-colon. All of them including declarations. So fix that, you left out a lot of semi-colons.

source_file.java:21: error: ')' expected
horasdia =Integer.parselnt(sc.nextLine();


It says "')' expected" because you left off the closing ) character in the method call.

There's a lot more but it's all the same sort of thing. You have random stuff like "repita" and "entao" in there which don't mean anything in Java (not by themselves, anyway).
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As someone who has done a fair bit of translation work between programming languages here's the top tip.
Do not simply try and convert the code on a line by line basis.
That way lies madness, even in ostensibly similar languages.

Understand what the code you are translating does, and then write it in the new language using the appropriate tools for that language.
This generally means breaking down the logic of the source into manageable chunks (usually the algorithm or business logic bits).

It's rather similar to translating between languages.
You wouldn't, for example, translate German to English on a word-for-word basis.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!