Answered step by step
Verified Expert Solution
Link Copied!

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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions