int a=1;
print (decimal2binary(a));
print(add(a,2));
int add(int a, int b) {
return a+b;
}
String decimal2binary(int number) {
while (number>0) {
int bin=number%2;
binaryString=binaryString+bin;
number=(number-bin)/2;
}
return binaryString;
}
Expected Java Code
...
private static String decimal2binary(int number) {
while (number>0) {
int bin=number%2;
binaryString=binaryString+bin;
number=(number-bin)/2;
}
return binaryString;
}
...
Actual Java Code
...
String decimal2binary(int number) {
while (number>0) {
int bin=number%2;
binaryString=binaryString+bin;
number=(number-bin)/2;
}
return binaryString;
}
...
resulting in errors like
Error on line 2 in file:/home/sergut/git/JDecafCompiler/tmp.jdc
Problem: non-static method decimal2binary(int) cannot be referenced from a static context
Error on line 12 in file:/home/sergut/git/JDecafCompiler/tmp.jdc
Problem: cannot find symbol
symbol: variable binaryString
location: class tmp
Error on line 12 in file:/home/sergut/git/JDecafCompiler/tmp.jdc
Problem: cannot find symbol
symbol: variable binaryString
location: class tmp
Error on line 15 in file:/home/sergut/git/JDecafCompiler/tmp.jdc
Problem: cannot find symbol
symbol: variable binaryString
location: class tmp
Java Decaf Code
Expected Java Code
Actual Java Code
resulting in errors like
Error on line 2 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: non-static method decimal2binary(int) cannot be referenced from a static context Error on line 12 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: cannot find symbol symbol: variable binaryString location: class tmp Error on line 12 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: cannot find symbol symbol: variable binaryString location: class tmp Error on line 15 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: cannot find symbol symbol: variable binaryString location: class tmp