Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i need help editing the following code that executes the following commands add(0,0) // 0+0 add(1,1) // 1+1 divide(1,2) //1/2 modulo(3,5) //3%5 modulo(6,6) //6%6 multiply(1,-10)
i need help editing the following code that executes the following commands
add(0,0) // 0+0
add(1,1) // 1+1
divide(1,2) //1/2
modulo(3,5) //3%5
modulo(6,6) //6%6
multiply(1,-10) //1*-10
multiply(3,3) //3*3
subtract(-1,-1) //-1- -1
subtract(1,1) //1-1
i also need to seperate these into two seperate files main and calculator.java in intelliJ
//
import java.util.*; class Calculator {// create variables to hold users number input private int a,b; HashMap Cal = new HashMap<>(); //use hashmap for storage public void setVariable(String varName,int a) { Cal.put(varName,a); } public void printAllVariables() //print all variables values { System.out.println("Value of A is: "+Cal.get("A")); System.out.println("Value of B is: "+Cal.get("B")); } public int getAddition() //addition { return Cal.get("A")+Cal.get("B"); } public int getSubtraction() //subtraction { return Cal.get("A")-Cal.get("B"); } public int getMultiplication() { return Cal.get("A")*Cal.get("B"); } public float getDivision() { return Cal.get("A")/(float)Cal.get("B"); } public int getModuloDivision() { return Cal.get("A")%Cal.get("B"); } } public class Main { public static void main(String[] args) { Calculator cal = new Calculator(); //create new object Scanner sc = new Scanner(System.in); //user input System.out.print("Enter value of a: "); int a=sc.nextInt(); //store info System.out.print("Enter value of b: "); int b=sc.nextInt(); cal.setVariable("A",a); cal.setVariable("B",b); System.out.println(); cal.printAllVariables(); System.out.println("Addition of "+a+" and "+b+" = "+cal.getAddition()); System.out.println("Subtraction of "+a+" and "+b+" = "+cal.getSubtraction()); System.out.println("Multiplication of "+a+" and "+b+" = "+cal.getMultiplication()); System.out.println("Division of "+a+" and "+b+" = "+cal.getDivision()); System.out.println("Modulo Division of "+a+" and "+b+" = "+cal.getModuloDivision()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started