Challenge

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);

}
}
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.