Project
Create a Scientific Calculator with the following operations-
- "+"-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.
It should run on an infinite loop and take inputs from the user for any operation they select based on the operation number on the list displayed to them. Save all the inputs, calculations and results in a file named “CalculationsHistory.txt”. Your code should follow all principles of Object-Oriented Programming. Create a report on how your software uses all the OOPs principles with examples from your code.
Code:// Java program for simple calculator
import java.io.*;
import java.lang.*;
import java.lang.Math;
import java.util.Scanner;
public class BasicCalculator {
public static void main(String[] args)
{
// stores two numbers
double num1, num2;
// Take input from the user
Scanner sc = new Scanner(System.in);
System.out.println("Enter the numbers");
// take the inputs
num1 = sc.nextDouble();
num2 = sc.nextDouble();
System.out.println("Enter the operator (+,-,*,/)");
char op = sc.next().charAt(0);
double o = 0;
switch (op) {
// case to add two numbers
case '+':
o = num1 + num2;
break;
// case to subtract two numbers
case '-':
o = num1 - num2;
break;
// case to multiply two numbers
case '*':
o = num1 * num2;
break;
// case to divide two numbers
case '/':
o = num1 / num2;
break;
default:
System.out.println("You enter wrong input");
break;
}
System.out.println("The final result:");
System.out.println();
// print the final result
System.out.println(num1 + " " + op + " " + num2
+ " = " + o);
}
}