# Help! Cannot complete calculator project

<Below this line, add a link to the EXACT exercise that you are stuck at.>

A basic calculator - Java. What am I doing wrong?

<In what way does your code behave incorrectly? Include ALL error messages.>
Calculator.java:32: error: ‘.class’ expected
^
Calculator.java:32: error: ‘;’ expected
^
Calculator.java:32: error: ‘;’ expected
^
Calculator.java:34: error: ‘.class’ expected
myCalculator.subtract(int aNum, int bNum);
^
Calculator.java:34: error: ‘;’ expected
myCalculator.subtract(int aNum, int bNum);
^
Calculator.java:34: error: ‘;’ expected
myCalculator.subtract(int aNum, int bNum);
^
6 errors

```

class Calculator {
public Calculator(){
}
public void add(int aNum, int bNum){
return aNum + bNum;
}
public void subtract(int aNum, int bNum){
return aNum - bNum;
}
public void multiply(int aNum, int bNum){
return aNum * bNum;
}
public void divide(int aNum, int bNum){
if(bNum==0) {
system.out.println(“Error! Dividing by zero is not allowed.”);
return 0;
} else {
return aNum / bNum;
}
}
public void modulo(int aNum, int bNum){
if(bNum==0){
system.out.prinln(“Error! Dividing by zero is not allowed.”);
return 0;
} else {
return aNum % bNum;
}
}

public static void main(String args) {
Calculator myCalculator = new Calculator();
myCalculator.subtract(int aNum, int bNum);
System.out.println(myCalculator.subtract(45, 11));

}
}

<do not remove the three backticks above>

If you’re unable to isolate the problems when there’s this much code, then do it with less code.

Start with just a class and a main method, compile it and run.
Add one very small part. Test it.
If it doesn’t work, reconsider what you just did, go back to testing.
If it does behave as you expect, add the next thing.

Essentially you’ve got a knowledge/experience debt and the solution to that is to only handle very small changes at a time.

create a class with a main method…
print out hello world…
create another method, empty…
call the empty method…
add a parameter to that method…
adjust the calling of the method to supply an argument…

and so on - compile and run each time you do something like that. And in particular, observe how the compiler reacts to your errors so that you can identify them later as well, when there is more code.

2 Likes

All right, thanks, I will try out that approach.

Let me just thank you again for this answer - I’ve just completed the exercise, but even more important, you gave me a method that I can use in future exercises. It kinda fits the expression:

I you catch a fish for a man he has food for 1 day, but if you learn him how to fish he has food for the rest of his life.

Great help, thanks a lot!

1 Like

This is Binoy,