Computer Science Canada

Calculater

Author:  r.m_spy [ Fri Apr 23, 2010 5:18 pm ]
Post subject:  Calculater

Java:

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


Author:  USEC_OFFICER [ Sat Apr 24, 2010 2:49 pm ]
Post subject:  RE:Calculater

Can you please explain what this is for? Just wondering. A preamble would have been nice.

Author:  r.m_spy [ Sat Apr 24, 2010 9:05 pm ]
Post subject:  RE:Calculater

A) calculator has you enter two numbers, and a symbol, and calculates

(press ? for help)

the other is a no-point applet


: