Create a scientific calculator using Java, Java Scientific Calculator, e.g logarithm, Factorial, etc.

  In this java tutorial, we will learn how to create a Java scientific calculator using basic java, which helps in to perform operations like Factorial, Square Root,logarithm, Factorial, etc.

There are some features of the Java Scientific Calculator

The following java scientific calculator will able to perform the following task:

  1. Addition(): To add one or more number.
  2. Subtraction(): subtract the numbers.
  3. Divide(): Divide the two numbers.
  4. Multiplication(): multiplication of numbers.
  5. Sin Value(): Get the value in radians as well as the degree of Sin.
  6. Cos Value(): Get the value in radians as well as the degree of Cos.
  7. Tan Value(): Get the value in radians as well as the degree of Tan.
  8. Log Value(): Find the value of Log Using Math.log() function.
  9. Factorial(): Calculate the factorial of given number.
  10. Square Root(): Find the square root of numbers. e.g. √36 is 6.

Table of Contents

Java Scientific Calculator Program

In the following program we uses a package called import java.util.*; The output of the program shown below:

   
 
    /*;==========================================
; Title: create a Java scientific calculator
; Author: codenaive littleboy8506@   
; Date:   13 Dec 2021
;==========================================*/
import java.util.*;
interface Defination
{   public void Add();
 public void Sub();
 public void Multi();
 public void SinValue();
    public void CosValue();
 public void TanValue();
 public void LogValue();
 public void Factorial();
 public void Swap();
 public void SquareRoot();
}
class Operation implements Defination 
{   public void Add()
 {   
  Scanner obj = new Scanner(System.in);
  int input,total=0;
  System.out.println("Enter The Range Of Number For Addition : ");
  try{
  input=obj.nextInt();
  
     int[] range=new int [input];
  for(int i=0;iinput)
  
    Total=input-input2;
    System.out.println("The Subtraction of "+input2+" - "+input+" is : "+Total);
  
    /*else
       Total=input-input2;
    System.out.println("The Subtraction of "+input+" - "+input2+" is : "+Total);*/
 }
 public void Multi()
 {   int i,Total=1,input;
  Scanner obj = new Scanner(System.in);
  System.out.println("Enter The Range Of Number For Multiplcation : ");
   input=obj.nextInt();
   int[] range=new int [input];
  for(i=0;i\nEnter The Number : ");
   input =obj.nextDouble();
   output = Math.log10(input);
   System.out.println("The Value of Log10("+input+") is "+output);
 }
 public void Factorial()
 {   System.out.println("Find a Factorial, Enter The Number : ");
  Scanner obj= new Scanner(System.in);
  long  input=obj.nextInt();
  long  factorial=1;
  for(long j=input;j>=1;j--)
  {
   factorial=factorial*j;
  }
  System.out.println("The Factorial OF "+input+" is "+factorial);
 }
 public void Swap()
 {   System.out.println(" Enter The Two Number : ");
  Scanner obj= new Scanner(System.in);
  System.out.print("Enter The Value Of A : ");
  int input=obj.nextInt();
  System.out.print("Enter The Value Of B : ");
  int input2=obj.nextInt();
  input =input+input2;
  input2=input-input2;
  input = input-input2;
  System.out.println("The Value Of A : "+input+"\nThe Value Of B : "+input2);
 }
 public void SquareRoot()
 {     Scanner obj=new Scanner(System.in);
    System.out.print("Enter The Number For SquareRoot Value ");
    double input =obj.nextInt();
    double output = Math.sqrt(input);
    System.out.println("The squareRoot value of "+input+" is "+output);
 }
}
class Choice extends Operation
{
public void Disp()
   { 
    Scanner obj=new Scanner(System.in);
    loop: while(true)
      {
 System.out.println("\n\nPlease Chose The operation :\n");
 System.out.println(" 1. Addition");
 System.out.println(" 2. Subtraction");
 System.out.println(" 3. Multiplication");
 System.out.println(" 4. Value Of Sin");
    System.out.println(" 5. Value Of Cos");
 System.out.println(" 6. Value Of Tan");
 System.out.println(" 7. Value Of Log");
 System.out.println(" 8. Factorial");
 System.out.println(" 9. Swaping");
 System.out.println(" 10.SquareRoot");
 System.out.println(" 11.Exit\n");
 System.out.print("Enter The choice Number : ");
 int input =obj.nextInt();
 switch(input)
         {     case 1:
     Add();
         break ;
       case 2:
          Sub();
         break;
       case 3:
         Multi();
      break;
       case 4:
      SinValue();
     break;
       case 5:
         CosValue();
      break;
    case 6:
       TanValue();
       break;
    case 7:
        LogValue();
     break;
     case 8:
      Factorial();
       break;
    case 9:
       Swap();
       break;
    case 10:
       SquareRoot();
       break;
    case 11:
       break loop;
        default :
      System.out.println("!Please Enter  Valid Number !");
    }
     } 
 }
}
public class Calculator
{
 public static void main(String[] arg)
 {
  Choice obj=new Choice();
  obj.Disp();
 }
}


Output:

Console Output

Java Scientific Calculator Console Output.

Leave a Reply

Your email address will not be published. Required fields are marked *