Project - Scientific Calculator
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Calcullator {
public static void main(String[] args) throws IOException {
Operations op = new Operations();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter("CalculationsHistory.txt");// run everytime if you want your history in
// "CalculationsHistory.txt"
System.out.println("WELCOME");
op.operations();
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of X");
double X = sc.nextDouble();
while (true) {
System.out.println("Which Operation you want to do in scientific calculator");
int choice = sc.nextInt();
if (choice == 1) {
System.out.println("YOU CHOOSE ADDITION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = X + Y;
System.out.println("Addition of X and Y = " + Z);
pw.write(X + "+" + Y + "=" + Z);
} else if (choice == 2) {
System.out.println("YOU CHOOSE SUBSTRACTION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = X - Y;
System.out.println("Substraction of X and Y = " + Z);
pw.write(X + "-" + Y + "=" + Z);
} else if (choice == 3) {
System.out.println("YOU CHOOSE MULTIPLICATION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = X * Y;
System.out.println("Multiplication of X and Y = " + Z);
pw.write(X + "*" + Y + "=" + Z);
} else if (choice == 4) {
System.out.println("YOU CHOOSE DIVISION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = (X / Y);
System.out.println("Division of X and Y = " + Z);
pw.write(X + "/" + Y + "=" + Z);
} else if (choice == 5) {
System.out.println("YOU CHOOSE RAISED TO POWER OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double z = Math.pow(X, Y);
System.out.println(X + " is raised to " + Y + " = "+Math.pow(X, Y));
pw.write(X + " is raised to " + Y + " = " + z);
} else if (choice == 6) {
System.out.println("YOU CHOOSE SQUAREROOT OPERATION");
double Z = Math.sqrt(X);
System.out.println("Square root of" + X + " is= " + Math.sqrt(X));
pw.write("Square root " + X + " is= " + Z);
} else if (choice == 7) {
System.out.println("YOU CHOOSE Nth ROOT OPERATION");
System.out.println("Enter the value of n");
double n = sc.nextDouble();
System.out.println(n + "th root of " + X + " is= " + Math.pow(X, 1 / n));
pw.write(n + "th root of " + X + " is= " + Math.pow(X, 1 / n));
} else if (choice == 8) {
System.out.println("YOU CHOOSE LOG OPERATION");
System.out.println(" Log of " + X + "is= " + Math.log(X));
pw.write(" Log of " + X + "is= " + (Math.log(X)));
} else if (choice == 9) {
System.out.println("YOU CHOOSE NATURAL LOG OPERATION");
System.out.println("Natural log of " + X + " is= " + Math.log10(X));
pw.write("Natural log of " + X + " is= " + Math.log10(X));
} else if (choice == 10) {
System.out.println("YOU CHOOSE SINE OPERATION");
System.out.println(" Sin(" + X + ")is= " + Math.sin(X));
pw.write(" Sin(" + X + ")is= " + (Math.sin(X)));
} else if (choice == 11) {
System.out.println("YOU CHOOSE SINE INVERSE OPERATION");
System.out.println(" isin(" + X + ")is= " + Math.asin(X));
pw.write(" isin(" + X + ")is= " + (Math.asin(X)));
} else if (choice == 12) {
System.out.println("YOU CHOOSE COS OPERATION");
System.out.println(" Cos(" + X + ")is= " + Math.cos(X));
pw.write(" Cos(" + X + ")is= " + (Math.cos(X)));
} else if (choice == 13) {
System.out.println("YOU CHOOSE COS INVERSE OPERATION");
System.out.println(" icos(" + X + ")is= " + Math.acos(X));
pw.write(" icos(" + X + ")is= " + (Math.acos(X)));
} else if (choice == 14) {
System.out.println("YOU CHOOSE TAN OPERATION");
System.out.println(" tan(" + X + ")is= " + Math.tan(X));
pw.write(" tan(" + X + ")is= " + (Math.tan(X)));
} else if (choice == 15) {
System.out.println("YOU CHOOSE TAN INVERSE OPERATION");
System.out.println(" itan(" + X + ")is= " + Math.atan(X));
pw.write(" itan(" + X + ")is= " + (Math.atan(X)));
} else if (choice == 16) {
System.out.println("YOU CHOOSE PLACE A NUMBER IN MEMORY FOR LATER USE OPERATION");
System.out.println("Stored number= " + X);
pw.write("Stored number= " + X);
} else if (choice == 17) {
System.out.println("YOU CHOOSE RECOVER THE NUMBER FROM MEMORY FOR IMMEDIATE USE OPERATION");
System.out.println("Recalling the number= " + X);
pw.write("Recalling the number= " + X);
System.out.println("Do you want to do any operation with recalled number...Y/N");
String YN = sc.next();
if (YN.equals("Y")) {
System.out.println("Which operation you want to do...");
op.operations2();
int choice1 = sc.nextInt();
if (choice1 == 1) {
System.out.println("YOU CHOOSE ADDITION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = X + Y;
System.out.println("Addition of X and Y = " + Z);
pw.write(X + "+" + Y + "=" + Z);
}
if (choice1 == 2) {
System.out.println("YOU CHOOSE SUBSTRACTION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = X - Y;
System.out.println("Substraction of X and Y = " + Z);
pw.write(X + "-" + Y + "=" + Z);
}
if (choice1 == 3) {
System.out.println("YOU CHOOSE MULTIPLICATION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = X * Y;
System.out.println("Multiplication of X and Y = " + Z);
pw.write(X + "*" + Y + "=" + Z);
}
if (choice1 == 4) {
System.out.println("YOU CHOOSE DIVISION OPERATION");
System.out.println("Enter the value of Y");
double Y = sc.nextDouble();
double Z = (X / Y);
System.out.println("Division of X and Y = " + Z);
pw.write(X + "/" + Y + "=" + Z);
}
} else {
System.out.println("Next operation");
}
} else if (choice == 18) {
System.out.println("YOU CHOOSE DECIMAL TO BINARY OPERATION ");
System.out.println("The value which you want to convert decimal to binary number is "+X);
System.out.println("Binary form of" + X + " is= " + Integer.toBinaryString((int) X));
pw.write("Binary form of" + X + " is= " + Integer.toBinaryString((int) X));
} else if (choice == 19) {
System.out.println("YOU CHOOSE BINARY TO DECIMAL OPERATION ");
System.out.println("Input the value(Y) which you want to convert binary to decimal number ");
String Y = sc.next();
String binaryString = Y;
int decimal = Integer.parseInt(binaryString, 2);
System.out.println(" Decimal form of" + Y + " is= " + decimal);
pw.write(" Decimal form of" + Y + " is= " + decimal);
} else if (choice == 20) {
System.out.println("YOU CHOOSE SIP CALCULATION OPERATION ");
System.out.println("Amount you invest through SIP(P) ");
double P = sc.nextDouble();
System.out.println("Compounded rate of raturn(i) ");
double i = sc.nextDouble();
System.out.println("Investment duration in months (n) ");
double n = sc.nextDouble();
var investment = P;
var annualrate = i;
var monthlyrate = annualrate / 12 / 100;
var months = n;
var futurevalue = 0;
futurevalue = (int) (investment * (Math.pow(1 + monthlyrate, months) - 1) / monthlyrate);
System.out.println("Future value(FV) is= " + futurevalue);
pw.write("Future value(FV) is= " + futurevalue);
} else {
System.out.println("Invalid Input, Please try again");
}
pw.close();
}
}
}