Project
import java.io.IOException;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
System.out.println("Welcome to the Calculator");
System.out.println("Enter the Method which You Used-" + "\n"+ "1.Add"+ "\n"+"2-Substract"+ "\n"+ "3-Multiply" + "\n"+ "4-Divide"+ "\n"+ "5-Rasing Power"+ "\n"+ "6- Square Root"+ "\n"+ "7-Nth Root"+ "\n"+ "8-Logarithmic"+ "\n"+ "9-Natural log"+ "\n"+ "10-Sine"+ "\n"+ "11-Inverse Sine"+ "\n"+ "12-Cosine"+ "\n"+ "13-Inverse Cosine"+ "\n"+ "14-Tangent"+ "\n"+ "15-Inverse tan"+ "\n"+ "16-stor"+ "\n"+ "17-recall"+ "\n"+ "18-Decimal to Binary"+ "\n"+ "19-Binary to Decimal"+ "\n"+ "20-Sip"+ "\n"+"Exit");
int X = 0;
while (true) {
System.out.println("Choose the number from the list of which you want the operation and enter it.");
Scanner sc=new Scanner(System.in);
int choice=sc.nextInt();
if(choice==1) {
System.out.println("Addition");
Scanner scanner = new Scanner(System.in);
double num =0;
double sum=0;
while (true) {
if (num == 5) {
break;
}
System.out.println("Input number");
sum = sum + Integer.valueOf(scanner.nextLine());
num = num + 1;
}
System.out.println("The sum of the numbers is " + sum);
}
else if(choice==2) {
System.out.println("Substract");
Scanner scanner = new Scanner(System.in);
double a = 0;
double b = 0;
double c= 0;
System.out.println("Enter first Number");
a=sc.nextInt();
System.out.println("Enter Second Number");
b=sc.nextInt();
c = a - b;
System.out.println("The substract of the numbers is " + c);
}
else if(choice==3) {
System.out.println("Multiple");
Scanner scanner = new Scanner(System.in);
double a;
double b;
double c;
System.out.println("Enter first Number");
a=sc.nextInt();
System.out.println("Multiply with Number");
b=sc.nextInt();
c = a * b;
System.out.println("The Multiple of the numbers is " + c);
}
else if(choice==4) {
System.out.println("Divided");
Scanner scanner = new Scanner(System.in);
double a=0; double b=0;
double c=0;
System.out.println("Enter first Number");
a=sc.nextInt();
System.out.println("Enter Second Number");
b=sc.nextInt();
c = a / b;
System.out.println("The Divided of the numbers is " + c);
}
else if(choice==5) {
System.out.println("Rasing Power");
double a =0;
double b=0;
double c = Math.pow(a, b);
System.out.println("Enter the number");
a=sc.nextInt();
System.out.println("Enter the power number");
b=sc.nextInt();
while (b != 0) {
c *= a;
--b;
}
System.out.println("Answer = " + c);
}
else if(choice==6) {
System.out.println("Square Root");
int n;
System.out.println("Enter any Number");
Scanner s= new Scanner(System.in);
n=s.nextInt();
double b =Math.sqrt(n);
System.out.println("Square root of" + n +" is "+b);
}
else if(choice==7) {
int root4th;
int n;
int value;
System.out.println("The Value of ");
Scanner s= new Scanner(System.in);
value=s.nextInt();
System.out.println("Enter any Number");
Scanner a= new Scanner(System.in);
n=a.nextInt();
root4th = (int) Math.pow(value, 1.0 / n);
System.out.println(root4th);
}
else if(choice==8) {
System.out.println("Logarithmic");
double a=0;
System.out.println("Enter any Number");
Scanner s= new Scanner(System.in);
a=s.nextInt();
double b =Math.log(a);
//System.out.println("Math.log(" + a + ")=" + Math.log(a));
System.out.println(b);
}
else if(choice==9) {
System.out.println("Natural log");
System.out.println("Enter the number of which you want the natural logarithmic value.");
float g = sc.nextFloat();
System.out.println(Math.log10(g));
System.out.println("\n");
}
else if(choice==10) {
System.out.println("Sine");
double a;
System.out.println("Enter a number");
Scanner s= new Scanner(System.in);
a=s.nextDouble();
double b=Math.toRadians(a);
System.out.println(Math.sin(b));
}
else if(choice==11) {
System.out.println("Inverse Sine");
double a;
System.out.println("Enter a number");
Scanner s=new Scanner (System.in);
a=s.nextDouble();
System.out.println(Math.asin(a));
}
else if(choice==12) {
System.out.println("Cosine");
double a;
System.out.println("Enter a number");
Scanner s= new Scanner(System.in);
a=s.nextDouble();
double b=Math.toRadians(a);
System.out.println(Math.cos(b));
}
else if(choice==13) {
System.out.println("Inverse Cosine");
double a;
System.out.println("Enter a number");
Scanner s=new Scanner (System.in);
a=s.nextDouble();
System.out.println(Math.acos(a));
}
else if(choice==14) {
System.out.println("Tangent");
double a;
System.out.println("Enter a number");
Scanner s= new Scanner(System.in);
a=s.nextDouble();
double b=Math.toRadians(a);
System.out.println(Math.tan(b));
}
else if(choice==15) {
System.out.println("Inverse Tangent");
double a;
System.out.println("Enter a number");
Scanner s=new Scanner (System.in);
a=s.nextDouble();
System.out.println(Math.atan(a));
}
else if (choice==16) {
System.out.println("Stor");
int a;
System.out.println("Enter the stored value");
Scanner num = new Scanner(System.in);
a=num.nextInt();
System.out.println(a);
System.out.println("\n");
}
else if(choice ==17) {
System.out.println("Recall");
System.out.println("Stored value is");
System.out.println(X);
System.out.println("\n");
}
else if(choice==18) {
System.out.println("Decimal To Binary");
int a = 0;
System.out.println("Enter Decimal Number");
Scanner Dec = new Scanner (System.in);
a = Dec.nextInt();
// converting to binary and representing it in a string
String bin = Integer.toBinaryString(a);
System.out.println(bin);
}
else if (choice ==19) {
String binaryString ;
System.out.println("Binary to Decimal");
Scanner Dec = new Scanner (System.in);
binaryString = Dec.nextLine();
//String binaryString="1010";
int decimal=Integer.parseInt(binaryString,2);
System.out.println(decimal);
}
else if(choice==20) {
System.out.println("Sip-Calculations of monthly, quarterly and yearly SIP calculations for compounding investments");
double fv;
double n;
double i;
double p;
double rate;
System.out.println("Enter the amount you invest");
p = sc.nextDouble();
System.out.println("Enter the percentage of expected annual rate of return");
rate = sc.nextDouble();
System.out.println("Enter the investment duration.");
n = sc.nextDouble();
i = rate / 100 / 12;
fv = (p * (Math.pow(1 + i, n) - 1) * (1 + i) / i);
System.out.println(fv);
System.out.println("\n");
}
else if(choice==21) {
break;
}
}
}
}