Not sure where I have gone Wrong


#1



public class Calculator {

public Calculator(){

}

public int add(int a, int b){
    return a + b;

}

public int subtract(int a, int b){
    return a - b;
}

public int multiply (int a, int b){
    return a*b;

}

public int divide (int a, int b){
    if (b == 0){
       System.out.println("Error! Dividing by zero is not allowed.");
       return 0;

    }

    else {
        return a/b;

    }

    public int modulo (int a, int b){
        if (b == 0){
            System.out.println("Error! Dividing by zero is not allowed.");
            return 0;
        }

        else {
            return a%b;
        }

        public static void main(String[] args){

            Calculator myCalculator = new Calculator();
            System.out.println(myCalculator.add(5, 7));
            myCalculator.subtract(45, 11);
}

}


Replace this line with your code.


#2

What's the issue?
What's your reasoning about said issue so far, where are you stuck?

There may be people willing to help, but a whole lot less if they also have to guess what the problem is (misplaced effort)


#3

This is what I get when I run the program.

Information:25/02/2017, 17:57 - Compilation completed with 11 errors and 0 warnings in 11s 647ms
Information:java: Errors occurred while compiling module 'Introduction_to_Java'
Information:javac 1.8.0_121 was used to compile java sources

Error:(34, 9) java: illegal start of expression
Error:(34, 26) java: ';' expected
Error:(34, 34) java: expected
Error:(34, 39) java: not a statement
Error:(34, 40) java: ';' expected
Error:(44, 13) java: illegal start of expression
Error:(44, 20) java: illegal start of expression
Error:(44, 26) java: ';' expected
Error:(44, 46) java: '.class' expected
Error:(44, 50) java: ';' expected
Error:(51, 2) java: reached end of file while parsing


#4

Start with the first error message (others may be the same problem, so fix that first and re-compile)
That error message says illegal start of expression, so you'd go to the line it says and reconsider where in the code that something is supposed to be allowed.

Something to note is that you have more opening curly braces than you have closing ones, so consider where those were supposed to go


#5

Thanks, I fugured it out. It's what you said, I had 2 open opening curly braces and didn't close them. Thanks


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.