You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* In addition to addition, subtraction, multiplication and division, a calculator program with advanced functions has been designed by performing mathematical operations such as mode taking, finding exponential numbers, factorial calculation, finding the area and perimeter of a rectangle.
*
*/
publicclassMain
{
staticintx, y, key;
publicstaticvoidgettingInputs()
{
Scannerinput = newScanner(System.in);
while(key!=9){
System.out.print("\n1-Addition\n2-Subtraction\n3-Multiplication\n4-Division\n5-Exponent\n6-Factorial\n7-Modular\n8-Rectangular Perimeter and Area\n9-Exit\n");
key = input.nextInt();
if(key==9){
System.out.println("See you later. Goodbye.");
break;
}
System.out.print("Enter Number \"x\": ");
x = input.nextInt();
if(key!=6){ //in factorial calculation, there is only one number.
System.out.print("Enter Number \"y\": ");
y = input.nextInt();
}
System.out.println("");
calculatorOperations();
}
input.close();
}
publicstaticvoidcalculatorOperations()
{
switch (key) {
case1:
System.out.println("Result of addition is " +(x+y));
break;
case2:
System.out.println("Result of subtraction is " + (x-y));
break;
case3:
System.out.println("Result of multiplication is " + (x*y));
break;
case4:
if(y!=0)
System.out.println("Result of division is " + ((float)x/(float)y));
else
System.out.println("You made an incorrect entry.");
break;
case5:
System.out.println("The result of the " + x + "^" + y + " exponent operation is: " + Math.pow(x,y));
break;
case6:
System.out.println("Result of factorial is " + facto(x));
break;
case7:
System.out.println("The result of the " + x + " % " + y + " modular operation is: " + x%y);
break;
case8:
System.out.println("The result of the perimeter of rectangular: " + 2*(x+y));
System.out.println("The result of the area of rectangular: " + (x*y));
break;
default:
System.out.println("An incorrect entry was made.");