Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions