Advanced calculator using JavaSript

import java.util.Scanner;
class Calculator_Developed
{
public static void main(String args[])
{
char operator;
System.out.println(“Enter to calculator”);
System.out.println(“Enter + to add numbers”);
System.out.println(“Enter – to subtract numbers”);
System.out.println(“Enter * to multiply numbers”);
System.out.println(“Enter / to divide numbers”);
System.out.println(“Enter P to square number”);
System.out.println(“Enter Q to cube number”);
System.out.println(“Enter S to find area and perimeter of Square”);
System.out.println(“Enter R to find area and perimeter of Rectangle”);
System.out.println(“Enter C to find area and perimeter of Circle”);
System.out.println(“Enter T to find area of Trapezium”);
System.out.println(“Enter I to find Simple Interest or Compound Interest”);
System.out.println(“Enter N for conversions”);
System.out.println(“Enter G for finding profit”);
System.out.println(“Enter L for finding loss”);
System.out.println(“Enter E to exit calculator”);
Scanner input=new Scanner(System.in);
System.out.println(“\n Enter our operator”);
operator=input.next().charAt(0);
if(operator==’E’)
{
System.out.println(“Thank you for using calculator”);
}
else if(operator==’+’)
{
double number1;
System.out.println(“Enter the value of number1”);
number1=input.nextDouble();
double number2;
System.out.println(“Enter the value of number2”);
number2=input.nextDouble();
double result=number1+number2;
System.out.println(“Addition of 2 numbers=”+ result );
}
else if(operator==’-‘)
{
double number1;
System.out.println(“Enter the value of number1”);
number1=input.nextDouble();
double number2;
System.out.println(“Enter the value of number2”);
number2=input.nextDouble();
double result=number1-number2;
System.out.println(“Subtraction of 2 numbers=”+ result );
}
else if(operator==’*’)
{
double number1;
System.out.println(“Enter the value of number1”);
number1=input.nextDouble();
double number2;
System.out.println(“Enter the value of number2”);
number2=input.nextDouble();
double result=number1*number2;
System.out.println(“Multiplication of 2 numbers=”+ result );
}
else if(operator==’*’)
{
double number1;
System.out.println(“Enter the value of number1”);
number1=input.nextDouble();
double number2;
System.out.println(“Enter the value of number2”);
number2=input.nextDouble();
double result=number1*number2;
System.out.println(“Multiplication of 2 numbers=”+ result );
}
else if(operator==’/’)
{
double number1;
System.out.println(“Enter the value of number1”);
number1=input.nextDouble();
double number2;
System.out.println(“Enter the value of number2”);
number2=input.nextDouble();
double result=number1/number2;
System.out.println (“Division of 2 numbers=”+ result );
}
else if(operator==’P’)
{
double number;
System.out.println(“Enter the value of number1”);
number=input.nextDouble();
double result=number*number;
System.out.println(“Square of number=”+result);
}
else if(operator==’Q’)
{
double number;
System.out.println(“Enter the value of number1”);
number=input.nextDouble();
double result=number*number*number;
System.out.println(“Square of number=”+result);
}
else if(operator==’S’)
{
double s;
System.out.println(“Enter the value of side”);
s=input.nextDouble();
double perimeter=4*s;
System.out.println (“Perimeter of square=”+ perimeter );
double area=s*s;
System.out.println (“Area of square=”+ area );
}
else if(operator==’R’)
{
double l;
System.out.println(“Enter the value of length”);
l=input.nextDouble();
double b;
System.out.println(“Enter the value of breadth”);
b = input.nextDouble();
double perimeter = (2*l)+(2*b);
System.out.println (“Perimeter of rectangle=”+ perimeter );
double area=l*b;
System.out.println (“Area of rectangle=”+ area );
}
else if(operator==’C’)
{
double r;
System.out.println(“Enter the value of radius”);
r=input.nextDouble();
double perimeter = 2*3.14*r;
System.out.println (“Perimeter of circle=”+ perimeter );
double area=3.14*r*r;
System.out.println (“Area of circle=”+ area );
}
else if(operator==’T’)
{
double a;
System.out.println(“Enter the value of 1st parallel side”);
a=input.nextDouble();
double b;
System.out.println(“Enter the value of 2nd parallel side”);
b = input.nextDouble();
double h;
System.out.println(“Enter the value of height”);
h = input.nextDouble();
double area= ((a+b)/2)*h;
System.out.println (“Area of rectangle=”+ area );
}
else if(operator==’A’)
{
double b;
System.out.println(“Enter the value of 2nd parallel side”);
b = input.nextDouble();
double h;
System.out.println(“Enter the value of height”);
h = input.nextDouble();
double area=(b*h)/2;
System.out.println(“Area of rectangle=”+ area);
}
else if(operator==’I’)
{
double p;
double r;
int t=1;
double si;
double a;
System.out.println(“\n Enter the Principal”);
p=input.nextDouble();
System.out.println(“\n Enter the Rate of Interest”);
r=input.nextDouble();
si=(p*r*t)/100;
System.out.println(“Simple Interst=”+si);
a=p+si;
System.out.println(“Amount=”+a);
}
else if(operator==’N’)
{
System.out.println(“1kilogram=1000gram”);
System.out.println(“1kilometer=100meter”);
System.out.println(“1centimeter=10millimeter”);
System.out.println(“1centigram=10milligram”);
System.out.println(“1kilolitre=1000litre”);
System.out.println(“1litre=1000milliliter”);
}
else if(operator==’G’)
{
double sellingprice;
System.out.println(“\n Enter the Sellingprice”);
sellingprice=input.nextDouble();
double costprice;
System.out.println(“\n Enter the Costprice”);
costprice=input.nextDouble();
double profit = sellingprice-costprice;
double profitpercentage=(profit/costprice)*100;
System.out.println(“Profit=” + profit);
System.out.println(“Profit%=”+profitpercentage);
}
else if(operator==’L’)
{
double sellingprice;
System.out.println(“\n Enter the Sellingprice”);
sellingprice=input.nextDouble();
double costprice;
System.out.println(“\n Enter the Costprice”);
costprice=input.nextDouble();
double loss = costprice-sellingprice;
double losspercentage=(loss/costprice)*100;
System.out.println(“Loss=” + loss);
System.out.println(“Loss%=”+losspercentage);
}
else
{
System.out.println(“You entered incorrect operator”);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s