Question: need help with a java caclulator class that does the following Add two integers Subtract two integers Multiply two integers Divide two integers Apply the

need help with a java caclulator class that does the following

Add two integers

Subtract two integers

Multiply two integers

Divide two integers

Apply the modulo operator on two integers

Set variable value Example: Calc1.setVariable("B", 5); using a HashMap instance variable imported

Print variable value Example: Calc1.printVariable("5"); prints 5

Print all variables doesnt take any parameters and prints the values stored for each variable

this is what i have, but im getting errors:

//package calc;

public class Calculator{

int add;

int subtract;

int multiply;

int divide;

int modulo;

public Calculator()

{

}

public Calculator(int additon)

{

add = addition;

}

public Calculator(int subtraction)

{

subtract = subtraction;

}

public static int add(int a,int b)

{

return a+b;

}

public static int subtract(int c, int d)

{

return c-d;

}

public static int multiply(int e,int f)

{

return e*f;

}

public static int divide(int g,int h)

{

if(Double.compare(h, 0)==0)

return Double.NaN;

else{

return g/h;

}

}

public static float modulo(float i, float j)

{

return i%j;

}

//public Calculator(float add,float subtract,float divide,float modulo)

//{

/* this.add = add;

this.subtract = subtract;

this.divide = divide;

this.modulo = modulo;

}*/

//method for returning addition

public float getAddition()

{

return add;

}

public float getSubtraction()

{

return subtract;

}

public float getDivision()

{

return divide;

}

public float getModulo()

{

return modulo;

}

}

//main

class Main {

public static void main(String[] args) {

//System.out.println("Hello world!");

// Calculator calc1 = new Calculator();

System.out.println(Calculator,add(1,3));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!