class calculator
{
public static void main(String[]args)
{
double num1,num2,ans;
char op;
System.out.println("Welcome to Calculator 1.0.");
System.out.println("");
System.out.println("Please enter your first number.");
num1=In.getDouble();
System.out.println("Please enter your operation. press ? for help.");
op=In.getChar();
if (op=='|')
{
ans=Math.sqrt(num1);
System.out.println("The Square root of "+num1+" is "+ans);
System.out.print("To end this program, enter another number. ");
}
if (op=='`')
{
ans=Math.round(num1);
System.out.println("If you round "+num1+", you get "+ans+".");
System.out.print("To end this program, enter another number. ");
}
System.out.println("Please enter your second number.");
num2=In.getDouble();
switch(op)
{
case '+':
ans=num1+num2;
System.out.println(num1+" + "+num2+" = "+ans);
break;
case '-':
ans=num1-num2;
System.out.println(num1+" - "+num2+" = "+ans);
break;
case '*':
ans=num1*num2;
System.out.println(num1+" X "+num2+" = "+ans);
break;
case '/':
ans=num1/num2;
System.out.println(num1+" / "+num2+" = "+ans);
break;
case '^':
ans=Math.pow(num1,num2);
System.out.println(num1+" ^ "+num2+" = "+ans);
break;
case '~':
System.out.println("Pie is equal to "+ Math.PI);
System.out.println("E is equal to "+ Math.E);
break;
case '?':
System.out.println("To add, use the symbol +");
System.out.println("To subtract, use the symbol -");
System.out.println("To multiply, use the symbol *");
System.out.println("To divide, use the symbol /");
System.out.println("To square, use the symbol ^");
System.out.println("To square root, use the symbol |");
System.out.println("To get the value of pie and e, use the symbol ~");
System.out.println("To round, use the symbol `");
break;
}
}
}
|