Project
package cal_demo;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
int option, a,b,c;
String d;
String binaryString="";
boolean decision;
System.out.println("We are here to create a calculator");
System.out.print("Do you want to switch on the calculator:");
try (Scanner sc = new Scanner(System.in)) {
decision = sc.nextBoolean();
do {
System.out.println("Following operations are available to perform:");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Power value");
System.out.println("6. Square Root of a number");
System.out.println("7. Nth root of a number");
System.out.println("8. Logarithmic value ");
System.out.println("9. Natural Logarithmic value");
System.out.println("10. Sine value");
System.out.println("11. Inverse sine value");
System.out.println("12. cos Value");
System.out.println("13. Inverse cos value");
System.out.println("14. Tangent value");
System.out.println("15. Inverse tangent value");
System.out.println("16. Decimal to Binary Conversion");
System.out.println("17. Binary to Decimal Conversion");
System.out.print("Enter the operations do you want to perform:");
option = sc.nextInt();
System.out.println("Choice of operation is:" + option);
switch (option) {
case 1:
System.out.println("Enter two numbers to be added:");
a = sc.nextInt();
b = sc.nextInt();
c = a + b;
System.out.print("Addition:" + c);
break;
case 2:
System.out.println("Enter two numbers to be subtracted:");
a = sc.nextInt();
b = sc.nextInt();
c = a - b;
System.out.print("subtracted:" + c);
break;
case 3:
System.out.println("Enter two numbers to be multiplied:");
a = sc.nextInt();
b = sc.nextInt();
c = a * b;
System.out.print("multiplied:" + c);
break;
case 4:
System.out.println("Enter two numbers to be divided:");
a = sc.nextInt();
b = sc.nextInt();
c = a / b;
System.out.print("divided:" + c);
break;
case 5:
System.out.println("Enter two numbers to get the power value:");
a = sc.nextInt();
b = sc.nextInt();
c = a ^ b;
System.out.println("The power value is" + c);
break;
case 6:
System.out.println("Enter the number:");
a = sc.nextInt();
c = (int) Math.sqrt(a);
System.out.println("Square root of the number is:" + c);
break;
case 7:
System.out.println("Enter the nth root of a number:");
a = sc.nextInt();
b = sc.nextInt();
c = (int) Math.pow(a, 1 / b);
System.out.println("Square root of the number is:" + c);
break;
case 8:
System.out.println("Enter the number to take log:");
a = sc.nextInt();
c = (int) Math.log10(a);
System.out.println("Logarithmic of the number is:" + c);
break;
case 9:
System.out.println("Enter the number to take natural logarithmic :");
a = sc.nextInt();
b = (int) Math.log(a);
System.out.println("Natural Logarithmic of the value is" + b);
break;
case 10:
System.out.println("Enter the number:");
a = sc.nextInt();
b = (int) Math.sin(a);
System.out.println("Sine Value of the number is:" + b);
break;
case 11:
System.out.println("Enter the number:");
a = sc.nextInt();
b = (int) Math.asin(a);
System.out.println("Inverse Sine value is:" + b);
break;
case 12:
System.out.println("Enter the number:");
a = sc.nextInt();
c = (int) Math.cos(a);
System.out.println("Cosine Value is:" + c);
break;
case 13:
System.out.println("Enter the number:");
a = sc.nextInt();
b = (int) Math.acos(a);
System.out.println("Inverse cosine value is" + b);
break;
case 14:
System.out.println("Enter the number:");
a = sc.nextInt();
c = (int) Math.tan(a);
System.out.println("Tangent Value is:" + c);
break;
case 15:
System.out.println("Enter the number");
a = sc.nextInt();
c = (int) Math.atan(a);
System.out.println("Inverse tangent value is:" + c);
break;
case 16:
System.out.println("Decimal to Binary:");
a = sc.nextInt();
d = Integer.toBinaryString(a);
System.out.println("Decimal to Binary Value is :" + d);
break;
case 17:
System.out.println("Binary to decimal:");
b = sc.nextInt();
c= Integer.parseInt(binaryString, b);
System.out.println("Binary to Decimal VAlue is :" + c);
break;
default:
System.out.println("This is a wrong choice");
break;
}
} while (decision == true);
}
}
}