Project
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
public class ScientificCalculator {
public static void main(String[] args) {
try {
PrintStream myConsole = new PrintStream(new File ("C://Users//raja//Documents//Calculations history.txt"));
Scanner sc = new Scanner (System.in);
int choice = 0;
do {
System.out.println(" ");
System.out.println("Which of the following operations do you want to execute?");
System.out.println("1. Add 2. Subtract 3. Multiply 4. Divide 5.Raised to the power 6.Square root 7.nth Root 8.log 9.logn 10.Sin ");
System.out.println("11. isin 12.cos 13. icos 14.tan 15. itan 16.d2b 17.b2d 18.sip 19.store 20.recall 21.Exit");
System.out.println("Enter the number of the operator");
int choice1 = sc.nextInt();
//Addition
if (choice1 ==1) {
double a ,b , Ans = 0;
System.out.println("Enter the first number");
a = sc.nextDouble();
System.out.println("Enter the second number");
b = sc.nextDouble();
Ans = a + b;
System.out.println("Result = "+ Ans);
}
//Subtract
else if (choice1 == 2) {
double a ,b , Ans = 0;
System.out.println("Enter the first number");
a = sc.nextDouble();
System.out.println("Enter the second number");
b = sc.nextDouble();
Ans = a - b;
System.out.println("Result = "+ Ans);
}
//Multiply
else if (choice1 == 3) {
double a ,b , Ans = 0;
System.out.println("Enter the first number");
a = sc.nextDouble();
System.out.println("Enter the second number");
b = sc.nextDouble();
Ans = a*b ;
System.out.println("Result = "+ Ans);
}
//Division
else if (choice1 == 4) {
double a ,b , Ans = 0;
System.out.println("Enter the first number");
a = sc.nextDouble();
System.out.println("Enter the second number");
b = sc.nextDouble();
Ans = a / b ;
System.out.println("Result = "+ Ans);
}
//Raised to the Power
else if (choice1 == 5) {
double a ,b , Ans = 0;
System.out.println("Enter the first number");
a = sc.nextDouble();
System.out.println("Enter the second number");
b = sc.nextDouble();
Ans = Math.pow(a, b) ;
System.out.println("Result = "+ Ans);
}
//Square Root
else if (choice1 == 6) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.sqrt(a) ;
System.out.println("Result = "+ Ans);
}
//nTH Root
else if (choice1 == 7) {
double a ,b , Ans = 0;
System.out.println("Enter the first number");
a = sc.nextDouble();
System.out.println("Enter the second number");
b = sc.nextDouble();
Ans = a* (1/b);
System.out.println("Result = "+ Ans);
}
//log
else if (choice1 == 8) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.log(a);
System.out.println("Result = "+ Ans);
}
//logn
else if (choice1 == 9) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.log1p(a);
System.out.println("Result = "+ Ans);
}
//Sin
else if (choice1 == 10) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.sin(a);
System.out.println("Result = "+ Ans);
}
//Sin Inverse
else if (choice1 == 11) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.asin(a);
System.out.println("Result = "+ Ans);
}
//Cos
else if (choice1 == 12) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.cos(a);
System.out.println("Result = "+ Ans);
}
//Cos Inverse
else if (choice1 == 13) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.acos(a);
System.out.println("Result = "+ Ans);
}
//Tan
else if (choice1 == 14) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.tan(a);
System.out.println("Result = "+Ans );
}
//Tan Inverse
else if (choice1 == 15) {
double a , Ans = 0;
System.out.println("Enter a number");
a = sc.nextDouble();
Ans = Math.atan(a);
System.out.println("Result = "+ Ans);
}
//Decimal to Binary
else if (choice1 == 16) {
int a , Ans ;
System.out.println("Enter a number");
a = sc.nextInt();
int i = 0;
int bin[]=new int[100];
bin[0]=0;
while(a>0)
{
bin[i++] = a%2;
a = a/2;
}
for(int j =i-1;j >= 0;j--)
{
System.out.print(bin[j]);
} System.out.println(" - Result");
}
//Binary to Decimal
else if (choice1 == 17) {
Scanner input = new Scanner( System.in );
System.out.print("Enter a binary number: ");
String binaryString =input.nextLine();
System.out.println("Output: "+Integer.parseInt(binaryString,2));
}
//SIP
else if (choice1 == 18) {
double M ; double J;double S ; double H ; double K; double Z;
System.out.println("Enter the amount you invested at regular intervals");
double P = sc.nextDouble();
System.out.println("Enter the number of payments you made");
double n = sc.nextDouble();
System.out.println("Enter the Peroidic rate of interest");
double i = sc.nextDouble();
J = (i + 1);
S = Math.pow(J, n);
K = (S - 1);
H = (1+i)/i ;
M = P*K*H;
System.out.println(M +" - Approx in a year");
Z = M/12;
System.out.println(Z + " - Approx in a month");
}
//Store
else if (choice1 == 19) {
System.out.println("Enter the variable");
String b = sc.next();
System.out.println("Enter the number you want to Store");
double a = sc.nextDouble();
String s = String.valueOf(a);
System.out.println(b+" ="+s);
}
//Recall
else if (choice1 == 20 ) {
System.out.println("");
}
}
while (choice != 21);
}
catch(FileNotFoundException fx) {
System.out.println(fx);
}
}
}
- Scientific Calculator - This program is made to do the calculations that are done in a scientific calculator. It can perform calculations like :-
- "+"-plus or addition
- "-" -minus or subtraction
- "*" -multiply by
- "/" -divided by
- "^"-raised to the power of- x raised to the y
- "Sqrt"- square root
- "Nrt"- nth root
- "log"- Logarithmic value
- "logn"- Natural log
- "sin"- Sine
- "isin" -Inverse sine
- "cos"- Cosine
- "icos"- Inverse cosine
- "tan"- Tangent
- "itan"- Inverse tan
- "stor" -place a number in memory for later use
- "recall"-recover the number from memory for immediate use
- "d2b" -Decimal to Binary number
- "b2d" -Binary to Decimal number
- "sip"- Calculations of monthly, quarterly and yearly SIP calculations for compounding investments.
This calculator carries out the calculations in the ScientificCalculator Class and gives the output in the console . It is a user friendly program with Questions for input of the number . Each operation has a different set of input questions according to the number of inputs that should be made for the particular operation . Most of the calculations are carried out using the Java.Math.lang .It has basic calculation operators along with many other difficult calculations . Log and natural log can be found for the desired number . Trigonometric functions like sin , cos ,tan can also be calculated including their inverse . Store function is used to initialize a value to the desired variable . Conversion operations of binary and deimals can also be carried out .Square root and nth Root can also be calculated. The yearly and monthly SIP can calculated after giving the correct inputs .The users have to choose the number specified for the operation they want to execute . This choice selection is done with the help of "if" and "else" statements . The program can be executed infinite times without breaking the continue flow of executions . The whole if and else statements are placed in a "do" "while" loop which makes it run at the desired number of times . If the user wants to start new calculations from the begin and want to exit .Then the choice "21" which is "Exit" will stop the program and the user can start a new set of calculations from the begining . All the outputs of the console are stored in the Calculations history text file . This program is based on the principles of Object Oriented Programing .The Scientific calculator has a main class , objects and loops and is very easy to use .