
Code a class that can be used to add, multiply, divide, get remainder, subtract two input numbers. Perform all kinds of boundary checks to ensure there is no overflow. (use wrapper classes to get constants to check against). Also add functionality to get the squareroot, log, round, ceil, floor of the input number.

import java.util.*;
public class Calculate {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Num1: ");
double num1 = input.nextDouble();
System.out.print("Num2: ");
double num2 = input.nextDouble();
if (num1 > 0 && num2 > 0) {
double sum = num1 + num2;
System.out.println("Sum= " + sum);
double diff = 0;
if (num1 > num2) {
diff = num1 - num2;
} else {
diff = num2 - num1;
}
System.out.println("Difference= " + diff);
double prod = num1 * num2;
System.out.println("Product= " + prod);
double rem = num1%num2;
System.out.println("Remainder= " + rem);
double div = num1/num2;
System.out.println("Division= " + div);
double sr1=Math.sqrt(num1);
double sr2=Math.sqrt(num2);
System.out.println("Square root of num1= " + sr1+" and num2= "+sr2);
double log1=Math.log(num1);
double log2=Math.log(num2);
System.out.println("Log of num1= " + log1+" and num2= "+log2);
double round1=Math.round(num1);
double round2=Math.round(num2);
System.out.println("Round-of of num1= " + round1+" and num2= "+round2);
double ceil1=Math.ceil(num1);
double ceil2=Math.ceil(num2);
System.out.println("Ceil of num1= " + ceil1+" and num2= "+ceil2);
double floor1=Math.floor(num1);
double floor2=Math.floor(num2);
System.out.println("Floor of num1= " + floor1+" and num2= "+floor2);
} else {
System.out.println("Invalid Numbers");
System.out.println("End of program");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.