Project
import java.lang.Math.*;
import java.util.Scanner;
public class ScientificCalculator {
int a, b;
Scanner sc = new Scanner(System.in);
int addition() {
System.out.println("Enter two number of addition");
a = sc.nextInt();
b = sc.nextInt();
return (Math.addExact(b, a));
}
int subtraction() {
System.out.println("Enter two number of subtraction : ");
a = sc.nextInt();
b = sc.nextInt();
return (Math.subtractExact(b, a));
}
int multiply() {
System.out.println("Enter two number of multiply : ");
a = sc.nextInt();
b = sc.nextInt();
return (Math.multiplyExact(b, a));
}
int divided() {
System.out.println("Enter two number of divided : ");
a = sc.nextInt();
b = sc.nextInt();
return (Math.floorDiv(b, a));
}
int power() {
System.out.println("Enter two number of power : ");
a = sc.nextInt();
b = sc.nextInt();
return ((int) Math.pow(a, b));
}
int sqaureRoot() {
System.out.println("Enter the number of square root : ");
a = sc.nextInt();
return ((int) Math.sqrt(a));
}
int nthRoot() {
System.out.println("Enter the number of nth root : ");
a = sc.nextInt();
return (Math.abs(a));
}
int logarithmicValue() {
System.out.println("Enter the number of logarithmicvalue() : ");
a = sc.nextInt();
return ((int) Math.log1p(a));
}
int naturalLog() {
System.out.println("Enter the number of naturalLog : ");
a = sc.nextInt();
return ((int) (Math.log(a)));
}
int Sine() {
System.out.println("Enter the number of sine : ");
a = sc.nextInt();
return ((int) Math.sin(a));
}
int Inversesine() {
System.out.println("Enter the number of Inversesine : ");
a = sc.nextInt();
return ((int) Math.asin(a));
}
int Cosine() {
System.out.println("Enter the number of Cosine : ");
a = sc.nextInt();
return ((int) Math.cos(a));
}
int Inversecosine() {
System.out.println("Enter the number of Inverse cosine : ");
a = sc.nextInt();
return ((int) Math.acos(a));
}
int Tangent() {
System.out.println("Enter the number of Tangent : ");
a = sc.nextInt();
return ((int) Math.tan(a));
}
int Inversetan() {
System.out.println("Enter the number of Inverse tan : ");
a = sc.nextInt();
return ((int) Math.tanh(a));
}
int stor() {
System.out.println("place a number in memory for later use: ");
a = sc.nextInt();
return (Math.getExponent(a));
}
int recall() {
System.out.println("recover the number from memory for immediate use : ");
a = sc.nextInt();
return(Math.getExponent(a));
}
int d() {
System.out.println("Enter the Decimal : ");
int a = sc.nextInt();
System.out.println("Binary equivalent of " + a + " is :");
System.out.println(Integer.toBinaryString(a));
return a;
}
int b() {
System.out.println("Enter the Binary : ");
int a = sc.nextInt();
System.out.println("Deminalequivalent");
System.out.println(Integer.parseInt(null, a));
return a;
}
int sip() {
System.out.println(
"Enter the Calculations of monthly, quarterly and yearly SIP calculations for compounding investments : ");
a = sc.nextInt();
b= sc.nextInt();
return (int) (Math.toRadians(a));
}
void scientific() {
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("1:Addition ");
System.out.println("2:Subtraction ");
System.out.println("3:Multiply");
System.out.println("4:Divided ");
System.out.println("5:raised to the power of- x raised to the y ");
System.out.println("6:square root ");
System.out.println("7:nth root ");
System.out.println("8:Logarithmic value ");
System.out.println("9; Natural log ");
System.out.println("10:Sine ");
System.out.println("11:Inverse sine ");
System.out.println("12:Cosine ");
System.out.println("13:Inverse cosine");
System.out.println("14:Tangent ");
System.out.println("15:Inverse tan ");
System.out.println("16:place a number in memory for later use");
System.out.println("17:recover the number from memory for immediate use ");
System.out.println("18:Decimal to Binary number ");
System.out.println("19:Binary to Decimal number ");
System.out.println(
"20:Calculations of monthly, quarterly and yearly SIP calculations for compounding investments");
System.out.println("Enter the number : ");
int choice = sc.nextInt();
ScientificCalculator obj = new ScientificCalculator();
int ans = 0;
switch (choice) {
case 1:
ans = obj.addition();
break;
case 2:
ans = obj.subtraction();
break;
case 3:
ans = obj.multiply();
break;
case 4:
ans = obj.divided();
break;
case 5:
ans = obj.power();
break;
case 6:
ans = obj.sqaureRoot();
break;
case 7:
ans = obj.nthRoot();
break;
case 8:
ans = obj.logarithmicValue();
break;
case 9:
ans = obj.naturalLog();
break;
case 10:
ans = obj.Sine();
break;
case 11:
ans = obj.Inversesine();
break;
case 12:
ans = obj.Cosine();
break;
case 13:
ans = obj.Inversecosine();
break;
case 14:
ans = obj.Tangent();
break;
case 15:
ans = obj.Inversetan();
break;
case 16:
ans = obj.stor();
break;
case 17:
ans = obj.recall();
break;
case 18:
ans = obj.d();
break;
case 19:
ans = obj.b();
break;
case 20:
ans = obj.sip();
break;
default:
System.out.println("wrong selection");
}
System.out.println("Answer =" + ans);
}
}
outputs
Enter the number :
1
Enter two number of addition
25 40
Answer =65
Enter the number :
2
Enter two number of subtraction :
30
28
Answer =-2
Enter the number :
3
Enter two number of multiply :
4
5
Answer =20
Enter the number :
4
Enter two number of divided :
24
2
Answer =0
Enter the number :
5
Enter two number of power :
30
20
Answer =2147483647
Enter the number :
6
Enter the number of square root :
6
Answer =2
Enter the number :
7
Enter the number of nth root :
8
Answer =8
Enter the number :
8
Enter the number of logarithmicvalue() :
23
Answer =3
Enter the number of naturalLog :
123
Answer =4
Enter the number :
10
Enter the number of sine :
25
Answer =0
Enter the number :
11
Enter the number of Inversesine :
28
Answer =0
Enter the number :
12
Enter the number of Cosine :
1
Answer =0
Enter the number :
13
Enter the number of Inverse cosine :
25644
Answer =0
Enter the number :
14
Enter the number of Tangent :
12
Answer =0
Enter the number :
15
Enter the number of Inverse tan :
432
Answer =1
Enter the number :
16
place a number in memory for later use:
2
Answer =1
Enter the number :
17
recover the number from memory for immediate use :
2
Answer =1
Enter the number :
18
Enter the Decimal :
35
Binary equivalent of 35 is :
100011
Answer =35
Enter the number :
19
Enter the Binary :
1010
Decimal equivalent of 1010 is :
10
Answer =1010
Enter the number :
20
Enter the Calculations of monthly, quarterly and yearly SIP calculations for compounding investments :
20000
50000
Answer =349